Reputation: 938
Using ' and ` leads to different results when setting a variable on the zsh shell script -
>>>one=`echo test`
>>>$one
>>>
>>>two='echo test'
>>>$two
>>>zsh: command not found: echo test
What the are the functions of the two?
Upvotes: 0
Views: 47
Reputation: 58908
This is not as simple as it may seem. Here is a shallow explanation of what is happening. Depending on the shell (and version), variables such as IFS
and other possibilities including at least aliases, any or all of the below may not apply, but I think it's a reasonable way of thinking about it in the normal case. Since I'm more familiar with Bash than Zsh I've included Bash references, but all this should apply to Zsh and other POSIX-ish shells as well.
Let's deconstruct these line by line.
one=`echo test`
:
`echo test`
is a command substitution. (In modern shells this form is discouraged in favour of $(echo test)
.) This is processed as follows:
echo test
) is word split into “echo” and “test”.execve
?
one
.$one
:
test
is indeed a command (and very likely a zsh built-in as well), so it runs fine and returns with an exit code of 1 because there were no arguments. See help test
or man test
for an in-depth explanation.two='echo test'
:
two
.$two
:
ln -s /bin/echo '/bin/echo test'
)zsh
helpfully prints an error message to this effect.Upvotes: 1