【问题标题】:Run a bash script via another bash script to delete a file is not working properly通过另一个 bash 脚本运行 bash 脚本以删除文件无法正常工作
【发布时间】:2015-02-14 01:45:30
【问题描述】:

我有一个 bash 脚本 start.sh,它调用另一个 run.sh,这将我带到另一个提示,我必须删除一个文件 file.txt,然后退出该提示。

当我从start.sh 内部调用run.sh 时,我看到了提示并且我相信它会删除file.txt 但内部/新提示等待我在脚本运行时退出它 - 意思它需要干预才能进行。如何在 bash 中避免它?

在 Python 中,我可以使用 Popen 并开始使用,但不确定 bash。

编辑:我想知道提供什么命令来退出 shell(从运行 run.sh 生成),这样我就可以回到启动“start.sh”的提示符。

Etan:回答你的问题

VirtualBox:~/Desktop/ > ./start

company@4d6z74d:~$ ->this is the new shell
company@4d6z74d:~$ logout ---> I did a "Control D here" so the script could continue.

start.sh 的相关部分:

/../../../../run.sh (this is the one that takes us to the new $ prompt)

echo "Delete file.txt " 
rm -f abc/def/file.txt

【问题讨论】:

  • run.sh 如何提示输入?可以显示run.sh的相关部分吗?

标签: bash command prompt


【解决方案1】:

您可以使用& 在后台运行run.sh。在 start.sh 中,您将通过 /path/run.sh & 调用脚本。现在,start.sh 将退出而不等待 run.sh 完成(在后台运行)。

【讨论】:

    猜你喜欢
    • 2012-12-15
    • 2011-06-13
    • 1970-01-01
    • 1970-01-01
    • 2023-01-13
    • 2023-03-04
    • 1970-01-01
    • 1970-01-01
    • 2021-04-16
    相关资源
    最近更新 更多