Last active
June 29, 2020 03:56
-
-
Save hyperupcall/be28f08fde6b6eccac2b0317ed8acac0 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
IsShellVariable() { declare -p $1; } &>/dev/null | |
PrintShellVariable() { | |
if IsShellVariable $@; then | |
echo [\'$1\' as Shell Variable]: "${!1}" | |
else | |
echo [\'$1\' as Shell Variable]: "NOT FOUND" | |
return 1 | |
fi | |
} | |
IsEnvVariable() { printenv $1; } &>/dev/null | |
PrintEnvVariable() { | |
if IsEnvVariable $@; then | |
echo [\'$1\' as Environment Variable]: "`printenv $1`" | |
else | |
echo [\'$1\' as Environment Variable]: NOT FOUND | |
fi | |
} | |
PrintVar() { | |
PrintShellVariable $1 | |
PrintEnvVariable $1 | |
echo | |
} | |
echo ASSIGNMENT | |
var1='hi i am var i' | |
PrintVar var1 | |
echo DECLARE / TYPESET | |
typeset -r var2='hi i am var2' | |
PrintVar var2 | |
echo PRINTF | |
printf -v var3 %s 'haiii i am var 3' | |
PrintVar var3 | |
echo READ / READARRAY / MAPFILE | |
read var4 <<< 'hoi! ;) var 4' | |
PrintVar var4 | |
echo EXPORT ASSIGNMENT | |
export var5='varrrr 5' | |
PrintVar var5 | |
set +o posix | |
echo SPECIAL BUILTIN NOT POSIX MODE | |
var6='sixth var ^w^' : | |
PrintVar var6 | |
echo REGULAR BUILTIN / COMMAND NOT POSIX MODE | |
var7='sevennth' read <<<'' | |
PrintVar var7 | |
set -o posix | |
echo SPECIAL BUILTIN POSIX MODE | |
var8='eighth var ^w^' : | |
PrintVar var8 | |
echo REGULAR BUILTIN / COMMAND NOT POSIX MODE | |
var9='9th rawwrr' read <<<'' | |
PrintVar var9 | |
set +o posix | |
echo HOME IS ENVIRONMENT VARIABLE | |
PrintVar HOME | |
echo BASHPID IS SHELL VARIABLE | |
PrintVar BASHPID | |
echo EXPORTED HOME | |
export BASHPID | |
PrintVar BASHPID | |
echo DEFINE FUNCTION | |
function fn { :; } | |
PrintVar fn | |
echo EXPORT FUNCTION | |
declare -rx fn | |
PrintVar fn | |
echo DECLARE X | |
declare -rx var10='tenth variable' | |
PrintVar var10 | |
echo ALIAS | |
alias var11='garrrhhh' | |
PrintVar var11 | |
echo ARRAY | |
#declare -a var12=("foxtrot oscar xray") | |
var12=("foxtrot oscar xray") | |
PrintVar var12 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment