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.

Revisions

  1. M1lan created this gist Jun 1, 2020.
    23 changes: 23 additions & 0 deletions bash_examplex_rh134.bash
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    #!/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