Last active
October 12, 2018 08:45
-
-
Save ikuwow/017570edeae5a4a80e46ace3bd0f2d0c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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