![](/img/trans.png)
[英]How can I use variables set from a terminal shell script in a new terminal window or tab? (OSX)
[英]OSX: Why does exit work when written manually in the terminal, but not with a shell script I run from the terminal?
osx中的此bash脚本不会退出脚本。 我已经更改了设置(如此处建议,以便在终端中写出口退出窗口关闭,并且我检查了如果在终端中写出口退出窗口,则关闭了窗口,这可能是什么原因?我重新启动了终端和Mac后,更改设置以查看是否可以解决问题,但是退出位置nr 1或脚本结尾处不起作用。
#!/bin/bash
PATH=/opt/local/bin:/opt/local/sbin:$PATH
read -p "What do you want to do?"
if test "$pass" = "f"
then
sh ~/f.sh
exit # nr 1
fi
if test "$pass" = "s"
then
sh ~/s.sh
exit # nr 1
fi
exit # nr 2
假设您的意思是当您这样做:
$ exit
您的终端退出。
但是当你跑步时
$ ./script.sh
您的终端无法退出。
答案是您的脚本是在其自己的shell进程中运行的,因此退出脚本时不会从终端中运行的shell中退出。
如果您使用
$ . script.sh
然后您将在当前Shell进程中运行脚本,所以exit
将退出正在运行的Shell,并导致终端退出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.