Throughout this book, you’ve been practicing running a single command. Unix doesn’t really care if you’re running a built-in command that came with the system, a program you installed later, or a script your best friend wrote—it’s all the same to Unix. Code Listing 9.1 shows some options on running a command.
ls
At the shell prompt, type the command and press .
/home/jdoe/scripts/ls
It’s certainly possible that you would want to write a script that would list the files in your directory in a special way—for example, a script to list the files and to save the listing into a new file for later reference. (You might name it something else but could certainly call it ls if you want to.) To run the specific script, enter the whole path to the script (so Unix doesn’t just run the first one it finds in your path). See Chapter 8 for more about path statements.
[jdoe@frazz Project]$ ls keep keeper.jpg kept kidder.txt kiddo → kidnews kidneypie kids kidupdate [jdoe@frazz Project]$ /bin/ls keep keeper.jpg kept kidder.txt kiddo → kidnews kidneypie kids kidupdate [jdoe@frazz Project]$ /home/jdoe/ → scripts/ls keep keeper.jpg kept kidder.txt kiddo → kidnews kidneypie kids kidupdate You listed these files. [jdoe@frazz Project]$ ls ; pwd keep keeper.jpg kept kidder.txt kiddo → kidnews kidneypie kids kidupdate /home/jdoe/Project [jdoe@frazz Project]$ |
✓ Tips
You can combine commands on the same line, as you’ve seen earlier in this book. Just use a ; to separate the commands, and you’re set. For example, you could do ls; pwd to list files and show the current directory.
If you use a && to combine commands, the system will run both in sequence but run the second only if the first succeeds. For example, you could use mv todolist todolist.done && touch todolist to move your to-do list to a different file and create a new to-do list. If the first command fails (for example, because you don’t have permission to create a new file), the second command won’t run.
3.145.130.31