knrafto / language-bash

Parse and pretty-print Bash shell scripts
BSD 3-Clause "New" or "Revised" License
35 stars 9 forks source link

Escape octal issue. #6

Closed Magicloud closed 10 years ago

Magicloud commented 10 years ago

Sorry, I do not know how to open issue 4 again. I found it worse.

$ cat /tmp/test.sh
echo -e 'x\064y'
$ echo -e 'x\064y'
x4y
λ>bash <- readFile "/tmp/test.sh"
λ>parse "" bash
Right (List [Statement (Last (Pipeline {timed = False, timedPosix = False, inverted = False, commands = [Command (SimpleCommand [] [[Char 'e',Char 'c',Char 'h',Char 'o'],[Char '-',Char 'e'],[Single [Char 'x',Char '\\',Char '0',Char '6',Char '4',Char 'y']]]) []]})) Sequential])
knrafto commented 10 years ago

echo is the one interpreting the backslash escapes, not Bash. This is the correct behavior. Bash should pass the string x\064y to echo, since it is single-quoted. The -e option makes echo print 4 instead of \064.