Skip to main content
16 events
when toggle format what by license comment
Oct 9, 2022 at 10:04 comment added Antonio Yes, 3 not works well. I have set up a terminal profile to run bash on startup. In this case I use bash but $SHELL returns zsh.
Apr 21, 2021 at 14:28 comment added Hi-Angel I wouldn't put ps -p$$ -ocmd= to the top of "reliable" list. I just was getting errors in my script, and then turned out the command returned not bash, not zsh, but "bash test.sh". So no, you can't rely on this.
Apr 8, 2021 at 16:11 comment added Denis Howe #1 is definitely heavier - running a command - but how is it more reliable that variables like $ZSH_VERSION?
S Sep 11, 2020 at 8:05 history suggested tomglynch CC BY-SA 4.0
made explanation for solaris and macOS clearer
Sep 11, 2020 at 5:46 review Suggested edits
S Sep 11, 2020 at 8:05
Dec 21, 2019 at 21:56 comment added xdevs23 $BASH_VERSION is enough to check whether the currently running is bash. I'd use this to detect whether any shell other than bash is being used.
Jul 31, 2018 at 11:48 comment added Peter Mortensen On HP-UX, ps -p$$ -ocommand= doesn't work either ("illegal option" for each of the letters after -o). The same with ps -p$$ -ofname.
S Jul 30, 2015 at 13:50 history suggested Evgeny CC BY-SA 3.0
Add note about -o option on OSX and on BSD
Jul 30, 2015 at 13:28 review Suggested edits
S Jul 30, 2015 at 13:50
Mar 18, 2014 at 1:51 comment added Keith Thompson If you're running tcsh, $tcsh and $version will be set. These are shell variables, not environment variables. If you're running a non-tcsh version of csh, I don't think there are any distinctive variables. And of course the syntax used to check variables differs between csh/tcsh on the one hand, and sh/ksh/bash/zsh on the other.
Oct 19, 2013 at 18:00 comment added duozmo On Mac, #1 is ps -p $$ -o comm="". Also, for those wondering, $$ is the shell process ID.
Aug 29, 2012 at 21:49 comment added iconoclast @geekosaur: maybe so, but $0 still seems more useful than $SHELL: wouldn't you agree? You could always pipe it through sed to remove the '-'.
Mar 18, 2011 at 3:51 comment added asoundmove ps -p$$ -ocmd="" is prettier :-)
Mar 18, 2011 at 2:44 comment added geekosaur I don't like $0 because it's more complicated: (1) it may be just the basename, (2) it may have '-' on the front to designate it as a login shell.
Mar 18, 2011 at 2:41 comment added Mikel Should you mention $0 too?
Mar 18, 2011 at 2:12 history answered geekosaur CC BY-SA 2.5