Last active
June 6, 2019 14:25
-
-
Save awwsmm/353577e5d97e135b5411e8cb6af39803 to your computer and use it in GitHub Desktop.
Get all environment and shell variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set | grep "^[A-Z]" | sed -e 's/[[:space:]].*//' -e 's/=.*//' | |
# tested on bash, ksh, tcsh, zsh | |
# Sources: | |
# https://askubuntu.com/a/275972/360539 | |
# https://stackoverflow.com/a/20348145/2925434 | |
# https://www.tutorialspoint.com/unix/unix-regular-expressions.htm | |
# https://stackoverflow.com/a/13202791/2925434 | |
# https://superuser.com/a/112837/728488 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# shell-agnostic (bash, csh, fish, ksh, sh, tcsh, zsh) script to determine shell type | |
# work in progress | |
# get this shell's variables | |
set | grep "^[A-Z]" | sed -e 's/[[:space:]].*//' -e 's/=.*//' > ~/.shellvars.tmp | |
# compare to bash | |
printf "bash " > ~/.shelllikeness.tmp | |
comm -12 ~/.shellvars.tmp ~/.bash.uniqvars | wc -l | sed 's/^ *//' | xargs printf >> ~/.shelllikeness.tmp | |
printf "/" >> ~/.shelllikeness.tmp | |
wc -l ~/.bash.uniqvars | sed 's/^ *//' | sed 's/ .*$//' >> ~/.shelllikeness.tmp | |
# compare to fish | |
printf "fish " >> ~/.shelllikeness.tmp | |
comm -12 ~/.shellvars.tmp ~/.fish.uniqvars | wc -l | sed 's/^ *//' | xargs printf >> ~/.shelllikeness.tmp | |
printf "/" >> ~/.shelllikeness.tmp | |
wc -l ~/.fish.uniqvars | sed 's/^ *//' | sed 's/ .*$//' >> ~/.shelllikeness.tmp | |
# compare to ksh | |
printf "ksh " >> ~/.shelllikeness.tmp | |
comm -12 ~/.shellvars.tmp ~/.ksh.uniqvars | wc -l | sed 's/^ *//' | xargs printf >> ~/.shelllikeness.tmp | |
printf "/" >> ~/.shelllikeness.tmp | |
wc -l ~/.ksh.uniqvars | sed 's/^ *//' | sed 's/ .*$//' >> ~/.shelllikeness.tmp | |
# compare to sh | |
printf "sh " >> ~/.shelllikeness.tmp | |
comm -12 ~/.shellvars.tmp ~/.sh.uniqvars | wc -l | sed 's/^ *//' | xargs printf >> ~/.shelllikeness.tmp | |
printf "/" >> ~/.shelllikeness.tmp | |
wc -l ~/.sh.uniqvars | sed 's/^ *//' | sed 's/ .*$//' >> ~/.shelllikeness.tmp | |
# compare to tcsh | |
printf "tcsh " >> ~/.shelllikeness.tmp | |
comm -12 ~/.shellvars.tmp ~/.tcsh.uniqvars | wc -l | sed 's/^ *//' | xargs printf >> ~/.shelllikeness.tmp | |
printf "/" >> ~/.shelllikeness.tmp | |
wc -l ~/.tcsh.uniqvars | sed 's/^ *//' | sed 's/ .*$//' >> ~/.shelllikeness.tmp | |
# compare to zsh | |
printf "zsh " >> ~/.shelllikeness.tmp | |
comm -12 ~/.shellvars.tmp ~/.zsh.uniqvars | wc -l | sed 's/^ *//' | xargs printf >> ~/.shelllikeness.tmp | |
printf "/" >> ~/.shelllikeness.tmp | |
wc -l ~/.zsh.uniqvars | sed 's/^ *//' | sed 's/ .*$//' >> ~/.shelllikeness.tmp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment