Shell hacking:从 csh 启动 bash

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18971107/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 06:39:52  来源:igfitidea点击:

Shell hacking: launch bash from csh

linuxbashshellunixcsh

提问by IDDQD

I am trying to set bash as my default shell in my university account.

我正在尝试将 bash 设置为我大学帐户中的默认 shell。

However, the traditional chshapproach does not work here because the university techs have disabled that as a startup shell. But, I can invoke bash by just calling bashfrom my terminal. So, I've developed a small hack that enables my current shell cshto start bash automatically by modifying my ~/.cshrcfile so that it calls bash from it. The thing is, I wish to set it up in such way that when I exit my bash session, I want it to close it's parent csh session as well. How can I do that?

但是,传统chsh方法在这里不起作用,因为大学技术人员已将其禁用为启动外壳。但是,我可以通过bash从我的终端调用来调用 bash 。所以,我开发了一个小技巧,csh通过修改我的~/.cshrc文件来使我当前的 shell能够自动启动 bash,以便它从中调用 bash。问题是,我希望以这样的方式设置它,当我退出我的 bash 会话时,我希望它也关闭它的父 csh 会话。我怎样才能做到这一点?

== EDIT ==

== 编辑 ==

Word of caution: as ajk warned about scripts running with csh, I found out the hard way that the login sequence is done precisely on that shell. I can no longer login into my machine now. I will have to contact my university techs about the removal of the rc file. Which I doubt will make them happy. :\

注意事项:正如 ajk 警告使用 csh 运行的脚本一样,我发现登录序列在该 shell 上精确完成的困难方式。我现在不能再登录我的机器了。我将不得不联系我的大学技术人员关于删除 rc 文件。我怀疑这会让他们开心。:\

So, take heed.

所以,要注意。

回答by ajk

Start bashlike this in your .cshrcfile:

bash在您的.cshrc文件中这样开始:

exec bash

Preferably, replace bashwith the full path to bash.

最好bash用完整路径替换bash.

Also, be careful if you have to run any script written in csh—if it doesn't use -f, it will execute your .cshrcfile before running. Since you exec bashin your .cshrc, the script probably won't run as intended. Writing scripts in cshis inadvisable, but I've been in at least one university course that required it.

此外,如果您必须运行任何用 编写的脚本,请小心csh- 如果它不使用-f,它将.cshrc在运行之前执行您的文件。由于您bash在exec中执行.cshrc,脚本可能不会按预期运行。编写脚本csh是不可取的,但我至少参加过一门需要它的大学课程。