Tuesday, November 3, 2009

Commands








 

 










Commands



The general format of a command typed to the shell is



command arguments



where command is the name of the program to be executed, and arguments are its arguments. The command name and the arguments are delimited by whitespace characters, normally the space, tab, and newline characters (changing the variable IFS affects this).



Multiple commands can be typed on the same line if they're separated by semicolons (;).



Every command that gets executed returns a number known as the exit status; zero is used to indicate success, and nonzero indicates a failure.



The pipe symbol | can be used to connect the standard output from one command to the standard input of another, as in





who | wc -l



The exit status is that of the last command in the pipeline. Placing a ! at the beginning of the pipeline causes the exit status of the pipeline to be the logical negation of the last command in the pipeline.



If the command sequence is terminated by an ampersand character (&),it is run asynchronously in the background. The shell displays the process id number and job id of the command at the terminal.



Typing of a command can continue to the next line if the last character on the line is a backslash character (\).



The characters && cause the command that follows to be executed only if the preceding command returns a zero exit status. The characters || cause the command that follows to be executed only if the preceding command returns a nonzero exit status. As an example, in





who | grep "fred" > /dev/null && echo "fred's logged on"



the echo is executed only if the grep returns a zero exit status.












     

     


    No comments:

    Post a Comment