Wednesday, November 13, 2013

Linux - Back To Basic Part 3 - Shell Command Substitution $(...)

This post, it will talk more about Command Substitution.

Command substitution happen during step 6 of command line processing. It will perform command substitution on any expression in the form of $(....)

$(COMMAND) is telling the shell to execute COMMAND and substitute it with the result.

Some examples,

1. $(echo ls)

a. It will first execute echo ls that is within $(...) and the echo output is ls
b. Next, it will replace $(echo ls) with ls. So, the final command is simply ls
c. The shell will execute ls as the final command

2. ls -al $(whereis ls)

a. It will first execute whereis ls within $(...) and echo the output such as ls: /bin/ls.exe /usr/bin/ls.exe /usr/share/man/man1/ls.1.gz
b. Next, it will replace $(whereis ls) with ls: /bin/ls.exe /usr/bin/ls.exe /usr/share/man/man1/ls.1.gz and the final command is ls -al ls: /bin/ls.exe /usr/bin/ls.exe /usr/share/man/man1/ls.1.gz
c. The shell will execute the final command and ls all given path in detail

No comments:

Post a Comment

Oracle - Reclaim disk space

Oracle does not release disk space even if you had delete the data or tablespace. If you have enterprise manager, you should use it to  rec...