June 2017
Beginner
502 pages
11h 26m
English
We already saw what a command substitution is:
zarrelli:~$ time=$(date +%H:%M) ; echo $time10:06
The output of a command gets stored as a string into a variable, and it is then available to be used in any way we need. So, for instance, we could well do this:
zarrelli:~$ myfile="myfile.txt.tgz" ; content=$(tar -tzf $myfile) ; echo $contentmyfile.txt
In this case, we used the command substitution to perform a test on a tar file whose name was provided by means of a variable. The output of the command substitution was then fed as an argument to echo, which showed us the outcome of the tar command. We could use an even more complex command inside the command substitution bit, but beware of some issues with escaping since ...
Read now
Unlock full access