Effective Methods of changing Shells in UNIX

bash unix tcsh

85 观看

2回复

0 作者的声誉

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 日

回应 2


0

1608 作者的声誉

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):

#!/bin/sh
作者: Mario 发布者: 2017 年 12 月 27 日

0

1660 作者的声誉

Always check your current shell by using :

echo $0

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 发布者: 2017 年 12 月 27 日
32x32