Question: How do I find out what Unix shell I’m currently running? Can you also explain how can I change my Unix shell both temporarily and permanently? (For example, from bash to tsh).
Answer: You can achieve these using $0, exec, chsh -s. In this article, let us review how to do these in detail.
1. What is my current Unix shell?
Use echo $0 command to get your current shell name as shown below.
$ echo $0 /bin/bash
2. How to change my current shell to another type – temporarily ?
Use exec command to change your shell temporarily as shown below.
$ echo $0 /bin/bash $ exec /bin/sh $ echo $0 /bin/sh
Note: The above change is temporary. When you relogin, you’ll go back to the original shell.
3. How to change my current shell to another type – permanently ?
To change your shell permanently, use chsh command as shown below.
$ chsh -s /bin/sh Password:
Note: The above change is permanent. Even after relogin, you’ll see only the new shell.
4. How can I find out all available shells in my system ?
All available shells are located in the /etc/shells file.
$ cat /etc/shells # /etc/shells: valid login shells /bin/csh /bin/sh /usr/bin/es /usr/bin/ksh /bin/ksh /usr/bin/rc /usr/bin/tcsh /bin/tcsh /usr/bin/esh /bin/dash /bin/bash /bin/rbash /usr/bin/screen /bin/ksh93
For changing your login shell, you can do only from the above output. But for changing the current shell, you can go to any available shell.
5. Installing New Shell
You can install a new shell (for example, ksh) as shown below. After installing new shell, you can use it as your permanent login shell, or temporary shell for your command line operations.
$ sudo apt-get install ksh
Comments on this entry are closed.
actually “exec” is not necessary to change your shell (run new one).
/bin/sh
or
/bin/tcsh
or something else to run a new shell.
hit ^D to close new shell and return to old shell.
tcsh on FreeBSD:
~ ~> echo $0
-csh
~ ~> echo $SHELL
/bin/csh
To get list of shells supported.
chsh -l
/bin/sh
/bin/bash
/sbin/nologin
/bin/zsh
Why do you use debian/ubuntu specific commands in an article named Unix shell tips? Is there an aptitude port for unix? Can you use that on freebsd? Or maybe type apt-get on an Irix system?
Is there a way to replace the current shell with sh (bourne) AND execute .profile (or some other file)? ksh can do this with the cmd ‘exec ksh’ if the ENV variable is set. The current shell is replaced with ksh and the file specified by ENV is run. I’m hoping to do the reverse (exec sh and have a script file run).
pls give ans how can know login shell?
echo $SHELL
is login
echo $0
is current
We have multiple ways to check the current shell.
ps $$
echo $SHELL
echo $0
I edit /etc/hosts file and try to save the changes but I cannot it gives an error massages /sbin/sh: wq! not found. when I checked the shell it is sh
I try to change the shell as /sbin/sh
it does not work. it saybad command.
Can anyone tell me how to communicate between bash shell and kclockwork shell i.e kwshell?
ps $$ will not give shell information
I want to switch my user to other user automatically without sudo changes in linux for that i used echo passward | su oracle but its won’t work could you please help for on these.