You are not logged in.
Here's some pseudo-code:
if [[ shell == bash ]]; then
do something
elif [[ shell == csh ]]; then
do something else
elif [[ shell == zsh ]]; then
do something different
else
return
fiMy question is: how do I detect what shell is running in the general case to execute the different code paths for each shell?
If I code something, it's probably at https://github.com/kellcodes
Do **NOT** expect a response from me.
Offline
Maybe with the SHELL variable?
> echo $SHELL
/bin/zshMore info: https://wiki.archlinux.org/title/Environment_variables
Last edited by Adriik (2022-06-18 23:04:05)
I'm just someone. Please use [code] [/code] tags.
Offline
I tried that. The problem on my system is that some shells are returning /usr/bin/<shell> instead of /bin/<shell> and I want this to work well in the future. I guess I could just use `rev | cut -d'/' -f 1 | rev`, it's just not as pretty.
If I code something, it's probably at https://github.com/kellcodes
Do **NOT** expect a response from me.
Offline
returning /usr/bin/<shell> instead of /bin/<shell>
/bin on Arch is a symlink to /usr/bin:
> ls -l /bin
lrwxrwxrwx 1 root root 7 dic 6 2021 /bin -> usr/binI'm just someone. Please use [code] [/code] tags.
Offline
I guess I could just use `rev | cut -d'/' -f 1 | rev`
Or just...
basename $SHELLOffline
/bin on Arch is a symlink to /usr/bin
Yes. Yes it is.
Either way, it doesn't look like my helper script will work, apparently writing a script that runs `eval "$(/home/user/anaconda3/bin/conda shell.bash hook)"` doesn't have the intended effect of setting up my user-installed anaconda environment.
basename $SHELL
I forget the specific case, but one time I spent the better part of 2 hours debugging a script only to find that the 'basename' command was returning trash and my silly little `rev | cut -d'/' -f 1 | rev` fix was the only way it would work. That's why I don't use basename.
Last edited by kev717 (2022-06-18 23:52:38)
If I code something, it's probably at https://github.com/kellcodes
Do **NOT** expect a response from me.
Offline
I'm not sure if using $SHELL is the best way to go (it doesn't work on my system), but if you do, don't use that three level pipeline with a rev | cut | rev, just use sed or awk:
echo $SHELL | sed 's|.*/||'
# or
echo $SHELL | awk -F/ '{print $NF;}'I suspect parsing /proc/$$/comm will be more reliable and may not need any processing.
EDIT: scratch that, /proc/$$/comm will fail too. But `readlink /proc/$$/exe` should be good, but then requires basename or trimming again.
Last edited by Trilby (2022-06-19 01:22:18)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
I forget the specific case, but one time … the 'basename' command was returning trash
Unescaped and unquoted blank in the variable … GI/GO problem.
Offline