Results 1 to 8 of 8
I have a bash script with the following:
LogFile=/tmp/`hostname`_show_config.`date +"%F_%H%M%S"`.log
Experimentation with "cat -v" indicates that "^M" is appended to the end of the filename. How do I get rid ...
- 04-24-2008 #1Just Joined!
- Join Date
- Apr 2008
- Posts
- 5
Need to create filename without trailing CR
I have a bash script with the following:
LogFile=/tmp/`hostname`_show_config.`date +"%F_%H%M%S"`.log
Experimentation with "cat -v" indicates that "^M" is appended to the end of the filename. How do I get rid of the CR, or what is the correct way of creating this filename?
- 04-24-2008 #2
Are you sure this is really so? I just pasted your command into a console to create a filename and then touched this into /tmp. ls /tmp gave a normal listing with no newline after the new filename. And when I used filename completion, there was no newline either.
"I'm just a little old lady; don't try to dazzle me with jargon!"
- 04-25-2008 #3Just Joined!
- Join Date
- Apr 2008
- Posts
- 35
It may be that you wrote the script in one place and ftp'ed it to another. Sometimes when you ftp a script (and the server daemon defaults to binary), it'll munge up your code like that.
If that's the case, when you ftp, just be sure to type
ascii
before your "put" or "get" command.
Hope that helped
, Mike
- 04-25-2008 #4Just Joined!
- Join Date
- Apr 2008
- Posts
- 5
hazel: That's the funny thing, if I do this from the console it works. If I put this into a bash script I get the extra CR appended to the end.
eggi: This file was not FTP'd. I created it using vi on the same system that I am testing it on. I checked the contents with 'cat -v' and see that each line ends with a single CR (^M) as I expected.
- 04-25-2008 #5Just Joined!
- Join Date
- Apr 2008
- Posts
- 35
Hmm...
That shoots down my one theory
Have you checked the TERM variable in your environment? It may possibly be an stty settings, but I think more likely TERM. Try:
TERM=vt100;export TERM
and create a new file with vi and check that for ^M's.
Of course, you're TERM may already be set to vt100. If so, and that setting is the issue, there are other options.
In your reply to Hazel, did you mean that if you type the line on the console it works correctly? That would make sense, because the ^M carriage-return would cause any negative effects.
Hope I came close this time
Best wishes,
Mike
- 04-26-2008 #6Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
If you are using vim to edit the bash script file, it's possible that vim is propagating the CR (^M) at the end.
You can use the last-line command:
to cause the CRs to be eliminated at the next write. The page at Change end-of-line format for dos-mac-unix - Vim Tips Wiki - a Wikia wiki provides more information.Code::set ff=unix
I tested this by creating a simple text file. I checked it with cat -v to ensure no CRs were in the file. I then re-edited the file, using the :set as above. The next cat -v showed the CRs at the ends of the lines. I copied that version of the file to a new file and used vi on it. The file-format was determined to be "dos". I assume that vim detected the CR and set the file format accordingly. Lines added to the file were appended with CRs automatically.
If you are not using vi/vim, let us know how you are editing the file ... cheers, drlWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 04-28-2008 #7Just Joined!
- Join Date
- Apr 2008
- Posts
- 5
Bingo.
The ':set ff=unix' & resave of the file did the trick and 'cat -v' shows no trailing CR at the end of each line.
Thanks.
- 04-28-2008 #8Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )


Reply With Quote
