Skip to content

Instantly share code, notes, and snippets.

@ikuwow
Last active October 12, 2018 08:45
Show Gist options
  • Save ikuwow/017570edeae5a4a80e46ace3bd0f2d0c to your computer and use it in GitHub Desktop.
Save ikuwow/017570edeae5a4a80e46ace3bd0f2d0c to your computer and use it in GitHub Desktop.
#!/bin/bash
## SC2007
## https://github.com/koalaman/shellcheck/wiki/SC2207
## Multiline output
var="foo
bar bar
hoge hoge
mog"
echo
echo '1. Simple echo:'
echo "$var"
echo
echo '2. SC2207 Unquoted expantion of array:'
array=($(echo "$var"))
for s in "${!array[@]}"; do
echo "$s: ${array[$s]}"
done
echo 'Result: also splitted by spaces'
echo
echo '3. Quoted expantion of array:'
array=("$(echo "$var")")
for s in "${!array[@]}"; do
echo "$s: ${array[$s]}"
done
echo 'Result: expanded as single value array'
echo
echo '4. Use mapfile:'
mapfile -t array <<< "$var"
for s in "${!array[@]}"; do
echo "$s: ${array[$s]}"
done
echo 'Result: expanded as default'
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment