我有一个Shell脚本,可以为我创建一个具有完整结构,git仓库等的项目。问题是执行测试后无法使用终端。这是我的脚本示例:
read -p "Have you created the remote repository : $repo.git ? [y/n] " ok
if [ $ok != "y" ]; then
echo "You must create the remote repository before."
exit 0;
fi
git init
# Rest of the script...
当我输入“ n”作为答案时,终端将显示此内容(对于非法语人群,“Opérationterminée”表示“操作结束”):
You must create the remote repository before.
logout
[Opération terminée]
而且我不能再使用它了。再次使用它的唯一方法是关闭选项卡,然后打开另一个选项卡。也许问题出在exit 0
?如何正确退出脚本?
谢谢。
由于这是从bash_profile运行的,因此exit 0
实际上根据其上下文关闭了外壳。通常,脚本就是调用该函数的函数,因此它不退出shell。例如,如果echo "hello world"; exit 0;
直接在外壳中运行,则它将关闭外壳,因为这是退出发生的上下文。
按照@ mklement0的建议,替换exit 0
为return
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句