Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
is called command substitution. I.e. that it will return the output of the operation inside the backticks. Since the operation
Code:
let num=num+1
does not return anything as output nothing will be printed on the screen by the 'echo'.
Also notice, that command substitution invokes a subshell. Therefore, after the operation is finished num will still have its old value as if nothing happened. Subshells do not export their values to the parent shell.
but what about this command when run in the bash :
echo "The world is a `echo "nice place to stay"`"
The world is a nice place to stay
In this case why the `echo "nice place to stay"` is working fine ?
Why does the sub-shell in this case returning correctly to the parent process ?
As I said earlier, command substitution returns the output of the command(s) run in the subshell.
Code:
`echo "nice place to stay"`
The above command's output is:
Code:
nice place to stay
The command
Code:
let num=num+1
on the other hand, does not have any output. It simply increments the variable 'num' quietly. Therefore, nothing is printed. Since the changed value of 'num' is lost after the subshell exits, the parent shell treats the value of num as if nothing happened.
BTW, you really should not use backticks `...` for command substitution. Use $(...) instead.
Read this link again, why $(...) is preferred over `...` (backticks): http://mywiki.wooledge.org/BashFAQ/082
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.