所以我最近注意到,在使用命令替换声明变量时,让我们这样说:
var=$(echo "this is running" > test; cat test)
Run Code Online (Sandbox Code Playgroud)
然后,它会运行(该文件test
将被创建),尽管我还不被称为(技术上的),我想这样:
var=$(echo "this is running" > test; cat test)
echo "$var" # is where i would "normally" call the variable
Run Code Online (Sandbox Code Playgroud)
在变量中声明命令替换时,如何防止命令替换实际运行,因此它仅在我调用所述变量时才实际运行?
PS:很清楚这是一个不好的例子,但它很好地展示了我的意思,尽管“无用的使用 cat”和“无用的使用 echo”......