[英]Bash script failing to execute bash script
我正在尝试运行一个脚本,该脚本将一些文件安装在用户指定的目录中。 用户指定目录后,我想将主文件传输到该目录,以便它可以在那里执行更多任务,然后在完成操作后最终将其自身删除。
#prompt for directory in which to build project
read -p "Drag and drop the directory in which you'd like to build this project: "
echo "reply is $REPLY"
cp ./myScript.sh $REPLY
/bin/bash $REPLY/myScript.sh
我已经有了执行该问题文件的脚本。 我尝试使用source $REPLY/myScript.sh
以及简单的sh $REPLY/myScript.sh
。 我收到错误/path/to/file/ is a directory
一定是它不知道我要运行myScript.sh,但是我不知道如何给它指定目录。
可能的原因是拖放操作在目录名称后放置了空格。
从而:
/bin/bash $REPLY/myScript.sh
会运行
/bin/bash /path/to/directory /myScript.sh
如果仅是标准空间,那么一个简单的修复方法是:
/bin/bash "${REPLY% }/myScript.sh"
您在read
命令中缺少该变量,因此很遗憾,它将因您所读取的任何内容未存储而失败。 您可以按以下方式替换read
命令。
#prompt for directory in which to build project
read -p "Drag and drop the directory in which you'd like to build this project: " REPLY
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.