8

Our company uses red hat linux system and allocate everyone an account in /home. Unfortunately, our system is using tsch, which is not favorable for me. Moreover, as I do not have the super user permission, I can not use the chsh command to change to bash for myself. Even worse, ypchsh is also unavailable for me. So, at last, I add the following lines into the .cshrc:

    bash
    echo $0

and configure the .bashrc appropriately (copying from the original .cshrc and fixing necessary syntax error). Now the apparent shell become bash (as can be shown from "echo $0" command).

Now the problem comes up:

When I use vim to edit a cpp file (e.g., Hello_World), and use ":!g++ -g Hello_World.cpp -o hw.out" in vim to compile the file, no result will be shown, and vim is quit with "bash" shown (as when a terminal is open), but without the usual "hit a key" to get back to my work in vim. In the Hello_World.cpp folder, there is a .Hello_World.cpp.swp file, but not hw.out. When vim Hello_World.cpp again, it turns out that this cpp file has been open.

However, if I g++ the cpp file in the folder but not using vim and :!, everything is OK. In fact, :! now seems to be illegal for vim.

If I use the original tcsh, everything is also OK.

How could I fix this curious error?

Thank you for your kind help in advance.

qing

BTW: I prefer bash to tcsh primarily due to its convenience of HISTIGNORE and HISTCONTROL, although tcsh also has histdup setting.

I found the following a little helpful but still not satisfactory for my problem.

How to run Unix commands from within Vim?

1

3 Answers 3

8

Put this in your .login script:

setenv SHELL /bin/bash
exec bash -l

The first line sets the SHELL environment variable. The second line replaces the tcsh with bash, but tells it to run as a login shell (so bash will process your .profile etc). You could add a -i option to make it interactive; it should not be necessary.

3
  • 2
    You can also put set shell=/bin/bash inside of VIM. That way, you can keep your shell, but use BASH in VIM and avoid the ! issues. However, I see that OP prefers bash anyway, so your solution will not only solve the VIM issue, but give OP their preferred shell.
    – David W.
    Nov 30, 2012 at 17:38
  • You're right, @DavidW. Since anyone can set their shell in vim (or vi) to whatever they like, it is basically impossible to restrict access to a system if you allow the user access to vi or vim. In times past, people have tried setting the shell to a special program that only executes certain commands. However, if one of those commands is vi or vim, then they have access to the system anyway. Nov 30, 2012 at 17:44
  • I feel sorry that as I am a newbie to this website, I don't know how to comment on this answer before. Thank you very much for your help. @JonathanLeffler & DavidW .
    – JQK
    Dec 2, 2012 at 12:31
2

The default shell for any user is stored in the /etc/passwd file. The user can change their default shell to any of the shells listed in /etc/shells by issuing the chsh command. Consult the manual pages of chsh(1) and shells(5) for more information.

This answer is "more correct" than the approach of replacing the current shell after logging in because it is unnecessary to start the undesired shell in the first place. That approach is useful only when the administrator has neglected the /etc/shells file and forgotten to add bash to it (never).

1
  • Hi, Pax, thank you for your reply. But I do not have the permission to execute chsh command. The administrator do not want to use chsh to change my shell, either. Thank you all the same.
    – JQK
    Dec 5, 2012 at 13:53
1

Thank you for all your great help.

Before giving the final solution I choose, I have to pointed out a mistake in my original question. My original .cshrc have the following three lines:

     bash
     source ~/.bashrc
     echo $0

I missed typing the second line before. Sorry.

Now, I tried these two methods, and the results are shown below.

1) .vimrc method

If I write

     bash
     source ~/.bashrc
     echo $0

in ~/.cshrc

and

     set shell=/bin/bash

in ~/.vimrc

without any ~/.login file, then vim and :!g++ is OK, but :!gdb a.out has some mistake. Furthermore, "echo $0" gives "bash" but "echo $SHELL" gives "/bin/tcsh". I don't know exactly the difference between $0 and $SHELL.

2).login method

If I write

     setenv SHELL /bin/bash
     bash
     source ~/.bashrc
     echo $0

in .login

but neither anything like "set shell=..." in ~/.vimrc nor "bash ..." in ~/.cshrc, everything is OK. Now, "echo $0" gives "bash" and "echo $SHELL" gives "/bin/bash".

The bash in second line can be replaced by "bash -l". It should be noted that if I replace it by "exec bash" or "exec bash -l", then I will not be able to log in my account. (The system automatically quit quickly.) I don't know why, either.

I think the second method is great. I appreciate your help very much.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .