Difference between revisions of "Bash operators"
From Linuxintro
imported>ThorstenStaerk |
imported>ChrisM |
||
Line 1: | Line 1: | ||
+ | = * and ? = | ||
+ | |||
+ | You may already know these used for so called "shell globbing" (pattern matching). * replaces an arbitrary amount of characters (including none), while ? replaces exactly one character. | ||
+ | |||
+ | These wildcards are actually bash operators! Imagine, we have the files a1, a2: | ||
+ | cp a* | ||
+ | now is a valid bash command which overrides one of these files with the other one. | ||
+ | |||
= $() = | = $() = | ||
The operator $() in the bash shell is replaced by the output of the command enclosed in the parentheses. It is equivalent to backticks (``), but can be cascaded more easily. | The operator $() in the bash shell is replaced by the output of the command enclosed in the parentheses. It is equivalent to backticks (``), but can be cascaded more easily. |
Revision as of 17:55, 31 March 2009
* and ?
You may already know these used for so called "shell globbing" (pattern matching). * replaces an arbitrary amount of characters (including none), while ? replaces exactly one character.
These wildcards are actually bash operators! Imagine, we have the files a1, a2:
cp a*
now is a valid bash command which overrides one of these files with the other one.
$()
The operator $() in the bash shell is replaced by the output of the command enclosed in the parentheses. It is equivalent to backticks (``), but can be cascaded more easily.
Examples:
rpm -ql $(rpm -qa)
for i in $(seq 1 1 100); do echo $i; done
$(())
The operator $(()) in the bash shell is replaced by the arithmetic result of the expression enclosed in the parentheses.
Examples:
# echo $((2*2)) 4