The dash character (-)

The dash is the option character, and usually, it denotes an optional parameter on a command line:

ps -ax

It is also used in parameter substitution as the prefix for the default parameter, and it is also used to redirect from/to stdin/stdout:

zarrelli:~$ cat -
1
1
2
2
3
3
^C

Or, it can do this:

zarrelli:~$ tar cvzf - $(ls text.file) > zipped.tgz
zarrelli:~$ tar -tf zipped.tgz
text.file

What we did is get the file name on the stdout using the command substitution, have it read from the stdin with the -, then the result of the tar operation redirected to the stdout to create the zipped file.

We can also use the dash to go back to our previous directory as held in the environmental $OLDPWD variable:

zarrelli:~$ mkdir -p dir1/dir2
zarrelli:~$ cd dir1/
zarrelli:~$ cd dir2/
zarrelli:~$ cd -
zarrelli:~$ pwd
dir1

Finally, in an arithmetic operations context, the dash means minus, so we can subtract a number from another.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.187.19