The od output clearly shows us that test.sh is not a shell script. Shell scripts are UNIX text files. UNIX text files have a single <newline> character as a line terminator on every line (not the DOS <carriage-return><newline> character pairs as line separators with no line terminator at the end of the file). The <carriage-return> characters in test.sh are extraneous characters at the end of all but the last line in your shell script. They are interpreted as part of the last string on each command line (i.e., as part of a filename operand, as the unknown string then<carriage-return> when the shell keyword then was expected, etc.) and are causing you lots of problems that are sometimes hard to diagnose because the diagnostic messages print the <carriage-return> characters but they frequently are invisible on the screen after they have been printed.
In the shell command language there are single-quotes ('), double-quotes ("), and back-quotes (`). Opening and closing double-quotes (“″) and opening and closing single-quotes (‘') may look nice in pretty-printed text, but they are syntax errors in a shell script.
Yes, you can use ls -t | head -n1 in a shell script and compare the results to the string saved in the variable FILENAME_WANTED by the command:
but, if instead of the above command you use the command:
where <CR> is a visual representation of the <carriage-return> character you have in your current version of test.sh, there will never be a match because the string saved in FILENAME_WANTED contains a trailing <carriage-return> character that is not present in the filename you are reading from ls.
If you want to use notepad instead of learning how to use vi, you must configure it to use UNIX line terminators; not DOS line separators and you must configure it to use shell command language single-quotes (not pretty-printed opening an closing single-quotes), double-quotes (not pretty-printed opening and closing double-quotes), and back-quotes (instead of pretty printed single-quotes) or learn to use the highly preferred $(command) form of command substitution instead of the obsolete `command` form of command substitution and stop using back-quotes in your shell scripts.
I have a file , the file content will be modified regularly , its structure as below, the lines are begins with "A" and "B" .
#vi file1
this is testing file
A aaaaa
B bbbbb
A ccccc
B ddddd
A eeeee
B fffff
A ggggg
B hhhhh
I would like to have a script to use the... (3 Replies)
Hi friends, I want to convert 24 hour timing to 12 hour please help me...
my data file looks like this..
13-Nov-2011 13:27:36 15.32044 72.68502
13-Nov-2011 12:08:31 15.31291 72.69807
16-Nov-2011 01:16:54 15.30844 72.74028
15-Nov-2011 20:09:25 15.35096 ... (13 Replies)
Hi,
My file
cat a.txt
Sat Nov 27 00:02:00 2010
00:02:00 Usr 27: Login by edi on batch. (452)
00:02:09 Usr 27: Logout by on batch. (453)
00:02:09 Usr 27: Login by edi on batch. (452)
00:02:22 Usr 27: Logout by on batch. (453)
00:02:22 Usr 27: Login by edi on batch.... (3 Replies)
Currently whenever i run date command output is shown like
Mon Apr 12 05:17:21 IST 2010
When its 17:17 Here.
How would i change it so that it should show.
Mon Apr 12 17:17:21 IST 2010 (8 Replies)
I have tried various arguments to get the date display as "Mar 10".
I have tried
date +"%c" -------> Wed Mar 10 11:51:21 EST 2010
date +"%b%d%Y_%H%M%S" --------> Mar102010_115121
date +"%b%d" -------> Mar10
date +"%t%b%e" ... (3 Replies)
Hello People,
How can I display the date in a continuous format along with the time as below :
20091001_154547
i.e yyyymmdd_hhmmss format.
Thanks. (3 Replies)
Hi,
I have some files in a folder with different time stamps and
I want to display the files which are older than 1 hour.
i tried with find.
need urgent help. (7 Replies)
Hi,
I have some files in a folder with different time stamps and
I want to display the files which are older than 1 hour.
i tried with find.
need urgent help. (3 Replies)