Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • Hmm but I don't think this will be any cleaner than sourcing it. Is there a file that both zsh and bash will read? Commented Oct 23, 2010 at 15:38
  • what makes you think that sourcing or creating a symlink is not a "clean" solution? Commented Oct 23, 2010 at 19:40
  • I just meant to say if needed, I'd like to source the file rather than to manage the symlink. I don't want to create a lot of dependency between files. Commented Oct 24, 2010 at 6:24
  • 1
    A more portable alternative to /bin/ls -l /proc/$$/exe is ps -o comm= -p $$. This isn't fully reliable because some shells behave differently depending on how they were invoked; in practice simply testing $0 in .profile is likely to be a better indication. But most shells that offer useful features (bash, ksh, zsh) can be simply recognized (and their version identified, which is a big plus) by testing some variables: $BASH, $BASH_VERSION, $BASH_VERSINFO; $KSH_VERSION, ${.sh.version}; $ZSH_VERSION. Commented Nov 20, 2010 at 0:10
  • echox, your case statement does not correctly detect zsh4 #Determine our shell without using $SHELL, which may lie shell="sh" if test -f /proc/mounts; then case $(/bin/ls -l /proc/$$/exe) in bash) shell=bash ;; *dash) shell=dash ;; *ash) shell=ash ;; *ksh) shell=ksh ;; *zsh) shell=zsh ;; #matches zsh4 esac fi Commented Jan 26, 2011 at 19:28