Skip to content

Instantly share code, notes, and snippets.

@M1lan
Created June 1, 2020 19:53
Show Gist options
  • Select an option

  • Save M1lan/be1e4018e5e21d9c649778578737747e to your computer and use it in GitHub Desktop.

Select an option

Save M1lan/be1e4018e5e21d9c649778578737747e to your computer and use it in GitHub Desktop.
just made this
#!/usr/bin/env bash
## bash examples for RH134 - milan santosi
## intro / explanation
# first line always magic line. it's needed when your O/S can't figure out from file-ending (.bash, .sh). IMHO the best way to find the bash shell interpreter (NOT just "/bin/sh") on any given unix environment (also: Docker environments!) is to ask "env" to return preferred path to bash. 99% of the time it's /usr/bin/bash and/or /bin/bash, but with asking env, we can be sure...
# file endings are optional. It matters more if chmod +x is set. The magic line is most important when script is called as argument of other command (such as `bash myscript.sh`). If script is not in $PATH, use "./" to call: `./script.sh`. Otherwise `echo $PATH` and move script to a directory that's listed. Or don't run script standalone but with `bash myscript.sh`
## simple if then
# this here is a so-called bashism / very bash-specific syntactic sugar
echo "output of bash-syntax using [["
[[ $1 = 'fedora' ]] && echo "it's fedora!" || echo "it's not fedora :("
# the universal, sh-compable syntax for exactly the same task is like this:
echo "output of old sh-syntax using if ["
if [ $1 = 'fedora' ] ;
then echo "it's still fedora!"
else echo "it's still not fedora :(("
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment