linux - shell字符串和程序执行

标签 linux shell

以下代码用于在准确位置创建文件。但是运行 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/

相关文章:

python - 运行 sudo 命令以在脚本中执行可执行文件

apache - 将 apache documentRoot 设置为 symlink(便于部署)

linux - 减去小时和分钟

linux - Bash如何对两个目录中的文件执行命令

c - 函数 _IO_file_init 和 _IO_file_fopen 的定义

mysql - 在文本文件中添加两列并加载到 sql

linux - awk 在第 1 列中打印大于零的行

c - setuid(0) 无法为 root 拥有的程序执行

linux - Nagios check_ntp_peer 不工作

PHP单元测试失败