Running a Command


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 wroteit's all the same to Unix. Code Listing 9.1 shows some options on running a command.

To run a command:

  • ls

    At the shell prompt, type the command and press .

To run a specific command:

  • /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 wayfor 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.

Code Listing 9.1. To run a script, command, or program, just enter the name or the path and the name at the shell prompt.

[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.





Unix(c) Visual Quickstart Guide
UNIX, Third Edition
ISBN: 0321442458
EAN: 2147483647
Year: 2006
Pages: 251

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net