I've searched for hours looking for the answer to this question which seems frustratingly simple...
I have a bash script which I've simplified to find the line that's stopping it from working and am left with:
#!/bin/bash
#
sed -i -e "s/<link>/\n/g" /usb/lenny/rss/tmp/rss.tmp
If I run this script, nothing happens to the file rss.tmp - but if I call this exact same sed command from the terminal, it makes all the replacements as expected.
Anyone have any idea what I'm doing wrong here?
Based on the discussion the issue sounds like it is a cygwin shell problem. The issue is that shell scripts may not have \r\n line terminations - they need \n terminations. Earlier versions of cygwin behaved differently. The relevant section from a Cygwin FAQ at http://cs.nyu.edu/~yap/prog/cygwin/FAQs.html
Q: Mysterious errors in shell scripts, .bashrc, etc A: You may get mysterious messages when bash reads your .bashrc or .bash_profile, such as "\r command not found" (or similar). When you get rid of empty lines, the complaints about "\r" disappears, but probably other errors remain. What is going on? The answer may lie in the fact that a text file (also called ASCII file) can come in two formats: in DOS format or in UNIX format. Most editors can automatically detect the formats and work properly in either format. In the DOS format, a new line is represented by two characters: CR (carriage return or ASCII code 13) and LF (line feed or ASCII code 15). In the UNIX format, a new line is represented by only one character, LF. When your .bashrc file is read, bash thinks the extra character is the name of a command, hence the error message. In Cygwin or unix, you can convert a file INFILE in DOS format to a file OUTFILE in Unix format by calling: > tr -d '\15' OUTFILE NOTE: If you now compare the number of characters in INFILE and OUTFILE, you will see that the latter has lost the correct number of characters (i.e., the number of lines in INFILE): > wc INFILE OUTFILE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With