Quantcast
Channel: How to determine the current interactive shell that I'm in (command-line) - Stack Overflow
Browsing all 30 articles
Browse latest View live

Answer by Pratik Gaurav for How to determine the current interactive shell...

Please try this helpful command.echo $SHELL

View Article



Answer by msalihbindak for How to determine the current interactive shell...

You can use echo $SHELL|sed "s/\/bin\///g"

View Article

Answer by calestyo for How to determine the current interactive shell that...

One way is:ps -p $$ -o exe=which is IMO better than using -o args or -o comm as suggested in another answer (these may use, e.g., some symbolic link like when /bin/sh points to some specific shell as...

View Article

Answer by Junaid for How to determine the current interactive shell that I'm...

Get it with the $SHELL environment variable. A simple sed could remove the path:echo $SHELL | sed -E 's/^.*\/([aA-zZ]+$)/\1/g'Output:bashIt was tested on macOS, Ubuntu, and CentOS.

View Article

Answer by Sean for How to determine the current interactive shell that I'm in...

I like Nahuel Fouilleul's solution particularly, but I had to run the following variant of it on Ubuntu 18.04 (Bionic Beaver) with the built-in Bash shell:bash -c 'shellPID=$$; ps -ocomm= -q...

View Article


Answer by Ivan for How to determine the current interactive shell that I'm in...

And I came up with this:sed 's/.*SHELL=//; s/[[:upper:]].*//' /proc/$$/environ

View Article

Answer by Shiva for How to determine the current interactive shell that I'm...

Do the following to know whether your shell is using Dash/Bash.ls –la /bin/sh:if the result is /bin/sh -> /bin/bash ==> Then your shell is using Bash.if the result is /bin/sh ->/bin/dash...

View Article

Answer by martin zahrubsky for How to determine the current interactive shell...

This one works well on Red Hat Linux (RHEL), macOS, BSD and some AIXes:ps -T $$ | awk 'NR==2{print $NF}'alternatively, the following one should also work if pstree is available,pstree | egrep $$ | awk...

View Article


Answer by Devang Paliwal for How to determine the current interactive shell...

There are many ways to find out the shell and its corresponding version. Here are few which worked for me.Straightforward$>echo $0 (Gives you the program name. In my case the output was...

View Article


Answer by wickles for How to determine the current interactive shell that I'm...

My solution:ps -o command | grep -v -e "\<ps\>" -e grep -e tail | tail -1This should be portable across different platforms and shells. It uses ps like other solutions, but it doesn't rely on sed...

View Article

Answer by user5659949 for How to determine the current interactive shell that...

I have a simple trick to find the current shell. Just type a random string (which is not a command). It will fail and return a "not found" error, but at start of the line it will say which shell it...

View Article

Answer by Matthew Stier for How to determine the current interactive shell...

My variant on printing the parent process:ps -p $$ | awk '$1 == PP {print $4}' PP=$$Don't run unnecessary applications when AWK can do it for you.

View Article

Answer by theoden8 for How to determine the current interactive shell that...

This is not a very clean solution, but it does what you want.# MUST BE SOURCED..getshell() { local shell="`ps -p $$ | tail -1 | awk '{print $4}'`" shells_array=( # It is important that the shells are...

View Article


Answer by ajaaskel for How to determine the current interactive shell that...

Grepping PID from the output of "ps" is not needed, because you can read the respective command line for any PID from the /proc directory structure:echo $(cat /proc/$$/cmdline)However, that might not...

View Article

Answer by David Ferenczy Rogožan for How to determine the current interactive...

I have tried many different approaches and the best one for me is:ps -p $$It also works under Cygwin and cannot produce false positives as PID grepping. With some cleaning, it outputs just an...

View Article


Answer by rominf for How to determine the current interactive shell that I'm...

None of the answers worked with fish shell (it doesn't have the variables $$ or $0).This works for me (tested on sh, bash, fish, ksh, csh, true, tcsh, and zsh; openSUSE 13.2):ps | tail -n 4 | sed -E...

View Article

Answer by Alex Dupuy for How to determine the current interactive shell that...

If you just want to check that you are running (a particular version of) Bash, the best way to do so is to use the $BASH_VERSINFO array variable. As a (read-only) array variable it cannot be set in the...

View Article


Answer by vadimbog for How to determine the current interactive shell that...

The following will always give the actual shell used - it gets the name of the actual executable and not the shell name (i.e. ksh93 instead of ksh, etc.). For /bin/sh, it will show the actual shell...

View Article

Answer by Ranjithkumar T for How to determine the current interactive shell...

Kindly use the below command:ps -p $$ | tail -1 | awk '{print $4}'

View Article

Answer by Peter Lamberg for How to determine the current interactive shell...

If you just want to ensure the user is invoking a script with Bash:if [ -z "$BASH" ]; then echo "Please run this script $0 with bash"; exit; fior refif [ -z "$BASH" ]; then exec bash $0 ; exit; fi

View Article
Browsing all 30 articles
Browse latest View live




Latest Images