Browse files

Tip for multi-shell environments

  • Loading branch information...
1 parent b004598 commit 37274ea0f5463edc46c33b70bb87b53570770654 eric committed Jan 31, 2011
Showing with 5 additions and 0 deletions.
  1. +5 −0
@@ -65,6 +65,11 @@ You also do not have specify a shell:
But you must pass the flag `--shell=SHELLNAME`.
+Best practices for multi-shell environments can use the following command:
+ --shell=`ps -p $$ | awk 'NR==2 {print $4}'`
+which will set the shell flag to the type of shell currently being ran.
Currently, the shells supported are tcsh and bash. However, I am assuming that
csh and zsh are supported as well since they are closely related to tcsh and

4 comments on commit 37274ea

ecki commented on 37274ea Mar 2, 2012

The ps command above will fail at least on FreeBSD where it is the 5th column:

# ps -p $$
91135  p7  S      0:00.05 /usr/local/bin/bash

I am not really shure in which context you can use such a construct to actually determine the shell (what shell is /bin/sh on Solaris?). So even using $SHELL will not really work well. Maybe the tool should inspect the environment itself, so it can implement some heuristics to find the correct shell?


et replied Mar 2, 2012

@ecki - I only tried on debian and red hat based systems.
Looking at this now (a year later), I don't know why I didn't just specify the column header.

This should do the trick:
ps -p $$ -ocmd | awk 'NR==2 {print $1}' | xargs basename

ecki replied Mar 2, 2012

@et The column is named "command" on FreeBSD's ps, so it does not work with -ocmd. If you trust the executable name, you can use echo $0.


et replied Mar 2, 2012

@ecki - IIRC, the problem with $0 is that it doesn't work when invoked within a sub-process.

-command as a column header works for my distro (Fedora)

ps -p $$ -ocommand | awk 'NR==2 {print $1}' | xargs basename


Please sign in to comment.