[Slackbuilds-users] bashisms?
Andrzej Telszewski
atelszewski at gmail.com
Sat Sep 12 09:23:54 UTC 2015
Hi,
I'm sorry to bother you again, it's not a bashism, but I thought I'll
share my finding with you.
I have never read my shell's manual (probably applies to all the shells)
and I was shocked by this behavior, particularly because I spent couple
of hours debugging my script. I should have read my shell's manual, sigh...
Test script:
#!/bin/sh
AAA=$'\n'$'\n'AAA$'\n'$'\n'
print_aaa() {
echo "$AAA"
}
echo "$AAA"
echo ======
echo "$(print_aaa)"
OUTPUT:
$ ./test.sh
AAA
======
AAA
$
Basically, command substitution $() removes trailing newlines...
I found it, when I was trying to check MD5 sum of variable, that
contained 2 trailing newlines at the end.
http://unix.stackexchange.com/questions/17747/why-does-shell-command-substitution-gobble-up-a-trailing-newline-char
http://wiki.bash-hackers.org/syntax/expansion/cmdsubst
Hope this helps.
--
Best regards,
Andrzej Telszewski
More information about the SlackBuilds-users
mailing list