Dear All,
How do I display the pathname to the BASH shell of the Linux Terminal?
Cheers,
Dear All,
How do I display the pathname to the BASH shell of the Linux Terminal?
Cheers,
There are two different things being discussed in the replies from and — showing your current working directory (what appears in the prompt) vs showing the pathname of the Bash executable itself. Both are useful, but they’re not the same: the environment variable your account is configured with may name your login shell, while the running shell process may be a different binary or a symlink. The examples below focus on reliably finding the path to the running shell on Linux and on how to put that path into your prompt if you want it visible.
To get the absolute path to the binary used by the current shell process (resolves symlinks):
readlink -f /proc/$$/exe If /proc isn’t available on your system, use the process listing instead:
ps -p $$ -o args= To find which bash would be executed from your PATH (not necessarily the one already running), use:
type -P bash If you want the shell path shown in your prompt, compute it once and reuse the value to avoid repeated work:
SHELLPATH=$(readlink -f /proc/$$/exe)
export PS1="$SHELLPATH \W\$ " Notes and troubleshooting: SHELL (as pointed out by ) normally reflects the login shell from account settings and may not match the binary returned above if you exec or start a different shell. For non-Linux Unixes (macOS/BSD) prefer the ps approach because /proc may be absent. If you only wanted the current working directory, ’s advice on showing that in the prompt is the right direction — showing the shell binary and showing the working directory are separate concerns.
Jump to Post— IsharaComix 97The path to the shell that is currently running in a terminal can be found in the 'SHELL' environment variable.
You can run 'echo $SHELL', which, on my machine, prints out '/bin/bash'.
Is this what you're looking for?
If you simply wish to display what directory you're currently in, use the print working directory command:
$ pwd
If you wish for the prompt to always contain the current directory, you will need to edit the value of PS1 in .bashrc (located in your home directory) to contain \w. To view the current value of PS1:
$ echo $PS1
You can edit this value with vi (or your favorite editor):
$ vi ~/.bashrc
Locate and add \w to the value of PS1, for example:
PS1="\u@\h:\w$ "
Which would make the bash prompt look something like:
keith@localhost:~/current/dir$
There is much more detailed information on editing .bashrc around the web. I hope this helps.
The path to the shell that is currently running in a terminal can be found in the 'SHELL' environment variable.
You can run 'echo $SHELL', which, on my machine, prints out '/bin/bash'.
Is this what you're looking for?
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.