I am a newbie to bash script programming and when I learned the variable expansion I amd puzzled by the variable.
1.when I want to define a variable,I can do as following:
name=foo
name="foo"
name='foo'
what's the difference between themm? 2.when I want to print a variable,I can do as following"
echo $name
echo "$name"
echo "$(name)"
3.I also encounter the part as following:
name=$(date)
what the "()" do,why it can resolve the command?
I googled my question and read some docs,eg ( http://www.serverwatch.com/tutorials/article.php/3898896/Single-vs-Double-Quotes-in-Bash.htm ) but i am still puzzling,can anyone explain it clearly?
name=foo
since the value is not present inside quotes, it won't accept the value which has spaces like name=foo bar
name='foo'
this won't expand the text present in the value. That is foo $bar
would be read as literal foo $bar
. It won't expand $b
name="foo"
values within the double quotes would be parsed or expanded.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.