Skip to content

Instantly share code, notes, and snippets.

@rndD
Created March 11, 2015 08:37
Show Gist options
  • Save rndD/b831b53314db8c1c07c8 to your computer and use it in GitHub Desktop.
Save rndD/b831b53314db8c1c07c8 to your computer and use it in GitHub Desktop.
print shortest env variable by key (work only in bash, not sh)
for i in `env`; do
key=${i%=*}
[[ -z $short_env ]] && short_env=$key;
[[ ${#key} -lt ${#short_env} ]] && short_env=$key;
done
echo "Shortest env variable: $short_env"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment