I'm trying to include some awk commands in a bash script, and I've run across some unexpected behavior. Can you give me a clue as to what I'm overlooking?
For example, given a file named list
:
1
2
3
4
This simple awk
command does what you'd expect:
$ awk -F, '{ print $1 }' list
1
2
3
4
But if I put this command in a bash script:
#!/bin/bash
echo "list:"
cat $1
echo "list after awk:"
echo `awk -F, '{ print $1 }' $1`
exit 0
I get this output:
$ ./script list
list:
1
2
3
4
list after awk:
1 2 3 4
The awk
in the bash script has mysteriously stripped away the carriage returns.
I've seen this behavior in bash on OS X as well as in zsh on BSD.
Any ideas?