以下代码用于在准确位置创建文件。但是运行 test.sh abc 的结果是
touch: missing file operand
#! /bin/sh
#test.sh
location='~/configuration/'$1
echo $location
touch `$location`
有什么问题吗?谢谢!
最佳答案
通过输入 $location
在反引号中,您正在尝试执行 $location
的值并将其用作 touch
的参数(参见 here ,第 3.4.5 节)只需执行:
touch $location
如果你运行 #!/bin/sh
与 -x
值(value),你会更清楚地看到什么bash
在你的 shell 脚本中做。这是调试脚本的一种非常有用的方法。
关于linux - shell字符串和程序执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12783263/