kno*_*t22 0 command-line bash scripts
我有一个包含以下代码行的 Bash 脚本:
echo "current directory is" $PWD
echo $PWD
# put current directory into a variable for use later in script
originalDirectory=$PWD
echo "contents of original directory variable:" originalDirectory
Run Code Online (Sandbox Code Playgroud)
输出的前 2 行有意义,但第三行没有意义。我希望它输出,contents of original directory variable: /media/sf_code/scripts
但它只是打印变量的名称。为什么它不在该字符串中的冒号后显示 originalDirectory 变量的内容?
最后一行应该是
echo "contents of original directory variable:" $originalDirectory
Run Code Online (Sandbox Code Playgroud)
没有$它是文本,而不是可变内容。所以你得到了文本。
所以这是一个预期的输出;-)