Skip to content

Instantly share code, notes, and snippets.

@EricCousineau-TRI
Created February 24, 2022 20:54
Show Gist options
  • Save EricCousineau-TRI/c3c074de657d063b772c9fa9b355319f to your computer and use it in GitHub Desktop.
Save EricCousineau-TRI/c3c074de657d063b772c9fa9b355319f to your computer and use it in GitHub Desktop.
#!/bin/bash
set -eux
flags=()
: "${flags[@]:-}" # bad
: "${flags[@]}" # good
flags=("thing w/ space" "other.thing")
: "${flags[@]:-}" # good
: "${flags[@]}" # good
: ${flags[@]} # bad (obvs)
<<'EOF'
$ bash --version | head -n 1
GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)
$ ./this_script.sh
+ flags=()
+ : ''
+ :
+ flags=("thing w/ space" "other.thing")
+ : 'thing w/ space' other.thing
+ : 'thing w/ space' other.thing
+ : thing w/ space other.thing
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment