Substitution Flashcards
1
Q
Back quotes
A
>MYDIR=dirname /usr/local/share/doc/foo/foo.txt
>echo $MYDIR /usr/local/share/doc/foo
- substitution by the result of the command inside the back quotes
2
Q
$( )
A
>MYDIR=$(dirname /usr/local/share/doc/foo/foo.txt)
>echo $MYDIR /usr/local/share/doc/foo
- Substitution by the result of the command inside the parenthesis behind the $ sign
3
Q
Substitute the result of piped commands
A
>MYFILES=$(ls /etc | grep pa)
>echo $MYFILES
pam. d passwd
* Note we’re listing the contents of the /etc directory whose name starts with the string “pa”