Re: builtin read -r and backslash-char escape sequences

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 03/08/2015 18:37, John Marshall wrote:
Problems with one of my scripts appear to have been caused by dash's read -r translating escape sequences (like \t) whereas several other shells read them literally.  For example:

$ printf '%s' '\a\t\x' > backslashes
$ dash -c 'read -r foo < backslashes; echo "$foo"' | cat -t
^G^I\x
$ bash -c 'read -r foo < backslashes; echo "$foo"' | cat -t
\a\t\x
$ ksh -c 'read -r foo < backslashes; echo "$foo"' | cat -t
\a\t\x

You're using echo to print what gets assigned to foo, but backslashes are not portable with echo. You probably noticed that already since you're using printf to determine what gets saved in the backslashes file. If you also use printf "%s\n" "$foo", you'll see that read works as you expect.

Cheers,
Harald van Dijk
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux