forked from koalaman/shellcheck
-
Notifications
You must be signed in to change notification settings - Fork 0
SC2005
Mingye Wang edited this page Oct 28, 2015
·
1 revision
echo "$(cat 1.txt)"
echo `< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c6`cat 1.txt # In bash, but faster and still sticks exactly one newline: printf '%s\n' "$(<1.txt)"
# The original `echo` sticks a newline; we want it too.
< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c6; echoThe command substitution $(foo) yields the result of command foo with trailing newlines erased, and when it is passed to echo it generally just gives the same result as foo.
One may want to use command substitutions plus echo to make sure there is exactly one trailing newline. The special command substitution $(<file) in bash is also un-outline-able.
Anyway, echo is still not that reliable (see SC2039#echo-flags) and printf should be used instead.