Conditional execution operators
||
You use the double pipe operator in the form
command1 || command2
In the above syntax, the second command executes only if the first command fails.
&&
You use the double ampersand operator in the form
command1 && command2
In the above syntax, the second command executes only if the first command executes successfully.
Command grouping operators
{ }
You can enclose multiple statements in braces ({}) to create a code block. The shell returns one exit status value for the entire group, rather than for each command in the block.
( )
You can enclose multiple statements in round brackets to create a code block. This code block functions in the same way as a code block enclosed in braces, but runs in a subshell.
I/O redirection operators
>
You use this operator to redirect command output to a file. If the specified file doesn't exist, the shell creates the file. If the file does exist, the shell overwrites it with the command output unless the noclobber environment variable is set.
>|
You use this operator to redirect command output to a file. If the specified file doesn't exist, the shell creates the file. If the file does exist, the shell overwrites it with the command output even if the noclobber environment variable is set.
>>
You use this operator to redirect command output to a file. If the file doesn't exist, the shell creates the file. If it does exist, the shell appends the new data to the end of it.
<
You use this operator to redirect command input from a file.
File descriptor redirection operators <&n
You use this operator to redirect standard input from file descriptor n.
>&n
You use this operator to redirect standard input to file descriptor n.
n< filename
You use this operator with a filename to redirect descriptor n from the specified file.
n> filename
You use this operator with a filename to redirect descriptor n to the specified file. Unlike ordinary redirection, this will not overwrite an existing file.
n>| filename
You use this operator with a filename to redirect descriptor n to the specified file, overriding the noclobber environment variable if it is set.
n>> filename
You use this operator with a filename to redirect a descriptor to the specified file. This will redirect to a file but, unlike ordinary redirection, this will append to an existing file.
Filename substitution
*
You use the * wildcard to match a string of any length.
?
You use the ? wildcard to match a single character.
[abc] , [a-c] , [a-c1-3]
You use square brackets to match only characters that appear inside the specified set. For increased convenience, you can specify multiple ranges.
!pattern
You use the ! operator with a pattern to perform a reverse match. The shell returns only filenames that don't match the pattern.
Command substitution
$(command)
You use this form of command substitution to resolve a command and pass its output to another command as an argument.
$(< filename)
You use this form of command substitution to pass the entire contents of a file to a command as an argument.
Tilde substitution
~
You use the ~ operator to instruct the shell to return the value of the $HOME variable.
~username
You use the ~ operator with a username to instruct the shell to return the full path of a specific user's home directory.
~+
You use the ~+ operator to instruct the shell to return the full path of the current working directory.
~-
You use the ~- operator to instruct the shell to return the full path of the previous working directory you used.
Miscellaneous syntax ;
If you enter several commands on the same line, you need to separate the commands with semicolons. The shell will execute each command successively once you press Enter.
\
You use a backslash to allow you to press Enter and continue typing commands on a new line. The shell will only begin executing your commands when you press Enter on a line that doesn't end in a backslash. Using a backlash in this way is known as backslash escaping.
&
You add a single ampersand at the end of a command to run that command as a background process. This is useful for tasks that are likely to take a long time to complete.
No comments:
Post a Comment