gpt4 book ai didi

linux - shell字符串和程序执行

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:53:20 27 4
gpt4 key购买 nike

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com