Dash : compatibility problem with a POSIX command?
I'm trying to write a script which will translate Ms-dos files (CR+LR style) to Unix style files (LF only).
For that purpose, I use the following grep command :
$ grep -l $'\r\n' dosfile.txt
where doxfile.txt is a file save by a windows text editor (notepad), containing some lines.
This command searches inside doxfile.txt for the end of line characters '\r\n' (or hex 0D0A) and prints the name of the file (in that case 'dosfile.txt' if there is a match.
In the terminal (which uses Bash), it works great and the name of the file is print when I run my command on the dosfile.txt.
The problem is with Dash. I made the following script for testing purposes :
#!/bin/sh
#sh is a symbolic link to dash
cd ~/Desktop # the text file is on my desktop
grep -l $'\r\n' dosfile.txt # exact same grep command
What you will notice (if your text file is truly of the ms-dos style) is that it does the inverse of the same grep command in the bash shell.
The command "grep -l $'\r\n' dosfile.txt" in the script returns nothing (normal behavior for an ms-dos text file would have been to print the name of the file, since '\r\n' exists)
Putting #!/bin/bash at the first line of my script fixed it for now.
Why would Dash not interpret rightfully the above grep command, considering the command is POSIX compliant (and so is supposed to be Dash) ?
Thank you!
Question information
- Language:
- English Edit question
- Status:
- Solved
- For:
- Ubuntu dash Edit question
- Assignee:
- No assignee Edit question
- Solved by:
- Robert Di Gioia
- Solved:
- Last query:
- Last reply: