0

I am trying to write a file that a user will source in order to modify their ld_library path. This will be different for each shell so I need to find theirs before I do this.

I have tried:

$SHELL

Unfortunately this will give the users shell but not necessarily the shell that they are in. If my normal shell is BASH but I swap into sh, it will return /bin/bash.

readlink -f /proc/$$/exe

This looked promising unfortunately a shell script actually spawns a new instance of bash, or whatever you put with the #! at the start.

Finally:

$0

This actually returns the name of the executable, rather than the shell. Which makes sense but it works as a shell command.

Any suggestions?

EDIT: So all of the suggestions from a similar thread will either return what is the users preferred shell, they will return the name of the executable itself, or they will return the path for the #! at the start of the code. None of these are particularly helpful.

BashOverride
  • 331
  • 1
  • 2
  • 13
  • 1
    What do you care about, the current shell or the user's chosen default shell? If it's the latter, you can look up the user's login shell with `getent passwd "$USER"`. – that other guy Jan 13 '16 at 19:06
  • $0 inside a bash script will return the name of the bash script itself. So that doesn't work. I care about the shell that they are currently using, not the one that is their default. I want to modify the library path for their current shell. – BashOverride Jan 13 '16 at 19:28
  • I would rather write a function to check if BASH_VERSION or KSH_VERSION or etc. are set. If none of them is available I would run specifics tests (using syntax peculiarities of each shell) to determine the current shell type... – mauro Jan 14 '16 at 02:50

0 Answers0