简体   繁体   English

从bash执行csh-script并且不要关闭csh-shell,但是仍然使用csh-prompt

[英]Execute csh-script from bash and dont close csh-shell, but remain with csh-prompt

I do have a tool that requires csh, but my default shell is bash. 我有一个需要csh的工具,但我的默认shell是bash。 I want/need to execute or source a csh-script from bash in the csh, and I want to end up with the csh-prompt after script execution. 我想/需要在csh中执行或从bash执行csh脚本,我想在脚本执行后最终得到csh-prompt。

From bash I can start the csh via csh and get the csh-prompt , then I can run any command in csh and remain with csh-prompt until I exit . 从bash我可以通过csh启动csh并获取csh-prompt ,然后我可以在csh中运行任何命令并保持csh-prompt直到我exit

I also can execute a command via csh -c 'ls' for example, but after the command execution the csh exits and I am back in bash. 我也可以通过csh -c 'ls'执行一个命令,但是在执行命令之后csh退出并且我回到了bash中。

I want something like this (as an example) 我想要这样的东西(作为例子)

[bash-prompt]# csh -c 'ls'
file1 file2 file3
[csh-prompt]# date
Tue Apr  2 15:33:35 CEST 2019
[csh-prompt]# exit
[bash-prompt]#

I don't find a way to achieve it - is it possible to execute a script and end up with the sub-shells prompt ? 我找不到实现它的方法 - 是否可以执行脚本并以子shell提示结束?

Just end your script with csh . 只需使用csh结束脚本即可。

The first thing to watch for is that your script exports all variables/functions that the subshell is supposed to see. 首先要注意的是,您的脚本会导出子shell应该看到的所有变量/函数。

The second thing is to watch out for non-interactive mode - you may later decide you want to run this script non-interactively (ie, just run the script, possibly with some other commands, and exit). 第二件事是注意非交互模式 - 您可能稍后决定要以非交互方式运行此脚本(即,只需运行脚本,可能还有其他命令,然后退出)。 You'll need to handle that case separately. 你需要单独处理这个案子。 I've had innumerable users put sh at the bottom of their .profile or something and then wonder why my tool that was using su to execute commands with dropped privileges (from root) was hanging. 我有无数的用户把sh在其底部.profile什么的,然后不知道为什么我的工具,用su执行与下降权限(从根部)命令挂。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM