退出自定义启动 shell 脚本后,退出到默认启动 shell?
如果我在这里使用了错误的语言,或者我问的是一个显而易见的问题,你必须原谅我,但这毕竟是我来这里的原因。
我刚刚开始掌握 shell 脚本编写,并编写了一个小脚本“作为自定义命令而不是我的 shell 运行”,以使我可能想做的事情变得更容易。这就是我所得到的。
#
# Custom console startup script.
#
path_to_scripts=~/Scripts
echo "Hello $USERNAME, what would you like to do?"
echo "Options:"
echo "-l Continue in local machine"
echo "-s Connect to server"
read response
case $response in
"l") echo "Contunie within local machine.";;
"s") $path_to_scripts/connect_to_server;;
*) echo "Invalid command. Exiting.";;
esac
因此,我的终端使用此脚本启动,如果我选择“s”,它会正常运行“connect_to_server”脚本并连接,然后我就进入了!
但是,当我输入无效命令或键入“l”退出并正常继续时,控制台会显示“子进程正常退出,状态为 0”。
我知道它刚刚退出并且脚本已经退出,但是我想要做的只是运行默认 shell,这样我就可以在 ~ 的本地计算机中,就好像 id 刚刚使用默认设置启动控制台一样。 为了做到这一点,我需要运行什么?
You have to excuse me if I use the wrong language here of if I'm asking an obvious but that is, after all, why I'm here.
I'm just getting to grips with shell scripting and have written a small script that is "Run as a custom command instead of my shell" to make things a little easier for the things I might want to do. Here's what I've got.
#
# Custom console startup script.
#
path_to_scripts=~/Scripts
echo "Hello $USERNAME, what would you like to do?"
echo "Options:"
echo "-l Continue in local machine"
echo "-s Connect to server"
read response
case $response in
"l") echo "Contunie within local machine.";;
"s") $path_to_scripts/connect_to_server;;
*) echo "Invalid command. Exiting.";;
esac
So my terminal starts up with this script and if I select 's' it runs the 'connect_to_server' script fine and connects then I'm in!
However when I enter an invalid command, or key in 'l' to exit and continue as normal the console says 'The child process exited normally with status 0.'
I know that it has just quit and the script has exited but what I want to do is just run the default shell so that I am then in my local machine at ~, as if id just started up console with default settings. What do I need to run in order to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
运行
exec "$SHELL"
将当前进程替换为普通 shell。Run
exec "$SHELL"
to replace the current process with your normal shell.