Effective Methods of changing Shells in UNIX
I used to work with UNIX a couple years ago, and I am just starting to get back into it again. I was wondering if anyone could help me with a question.
For example, if I am in bash, I say
chsh --shell /bin/tcsh after this I am prompted to enter my password. If I try to say
echo $SHELL it will not tell me I have changed shells. It still tells me I am in bash, not C shell. So I have to exit and restart. Once I log back it, then it tells I am in C shell.
Is there a more effective method to change shells? One that does not require me having to log in and out?
Thank you in advance.作者: user8915618 的来源 发布者: 2017 年 12 月 27 日
chsh(1): change your login shell
Once you change your shell with chsh, it should automatically login to that shell every time you open a terminal.
If you want to use a different shell temporary, just run that shell directly: "tcsh", "zsh", etc..
If you want to use a particular shell for a script use shebang "#!".
Example -- The following on the first line of a shell script will ensure the script is run with sh (and you can do this for any shell available on your system):
作者: Mario 发布者: 27.12.2017 05:11
Always check your current shell by using :
That way you will get the exact process ( your current shell ) you are running. If you print $SHELL it will return to you the default shell that will be open when you login to the server which unless that's what you need its not reliable.
ubuntu$ echo $SHELL /bin/bash ubuntu$ echo $0 -bash ubuntu$ sh \[\e[31m\]\u\[\e[m\]$ echo $SHELL /bin/bash \[\e[31m\]\u\[\e[m\]$ echo $0 sh \[\e[31m\]\u\[\e[m\]$
Regards!作者: Matias Barrios 发布者: 27.12.2017 07:09