I came across the following command
sudo chown `id -u` /somedir
And I wonder what is the meaning of the ` symbol. I noticed for instance that while the command above works well the one below does not
sudo chown 'id -u' /somedir
This is a backtick. Backtick is not a quotation sign, it has a very special meaning. Everything you type between backticks is evaluated (executed) by the shell before the main command (like
effectively runs (depending on your user ID) is:
Have a look at this question to learn why, in many situations, it is not a good idea to use backticks.
I would like to add few more points here.
The command substitution can be done in two ways one is using
can be preferred over the other.
This symbol mean that whatever inside it, is interpreted as the result of that command.
The above resutl will be that the
The backtick ` runs the contents of the enclosed string, so something like this
will find out the path to the hostname command, and then tell you how it was built.
The command that you put in your question runs
One note of clarification rarely covered:
Backticks (sometimes also called Graves because it doubles as a common accent in French and other languages) substitute the Standard Output only, but not the Standard Error.
So to continue the previous example:
will work as expected, but in:
In this case,
will essentially reduce to just:
which, of course, is bad usage, and will return a Usage error.