通过 SSH 运行源脚本名称时退出脚本
我有一个包含许多选项的脚本,其中一个选项集应该更改目录,然后退出脚本,但是通过 ssh 运行源代码以使其在父级中更改,然后退出 SSH 是否有另一种方法这样做以使其不退出?我的脚本位于 /usr/sbin 目录中。
I have a script with a number of options in it one of the option sets is supposed to change the directory and then exit the script however running over ssh with the source to get it to change in the parent it exits SSH is there another way to do this so that it does not exit? my script is in the /usr/sbin directory.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试让脚本运行子 shell,而不是使用任何方法来“更改父级中的[目录]”(假设您让子级打印出 cd 命令并让父级执行类似
eval "$(script --print-cd)"
)。因此,不要添加--print-cd
选项,而是添加一个--subshell
选项来启动$SHELL
的新实例。如果您无法编辑脚本本身,您可以制作一个包装器(假设您有权在“服务器”上创建新的持久文件):
You might try having the script run a subshell instead of whatever method it is using to “change [the directory] in the parent” (presumably you have the child print out a
cd
command and have the parent do something likeeval "$(script --print-cd)"
). So instead of (e.g.) a--print-cd
option, add a--subshell
option that starts a new instance of$SHELL
.If you can not edit the script itself, you can make a wrapper (assuming you have permission to create new, persistent files on the ‘server’):