Hello,
I am a begginer on shell scripting and I need a simple advice.
I have the following script.
The output of DATE is gathered from Oracle and it will be 101115 (for todays date)
Therefore the DAY will be sed-ed , and it contains 15
#!/bin/sh
DATE=`${LIB}/dt_YYMMDD 0`
DAY=`echo $DATE| sed 's/....\(.*\)/\1/'`
if [ $DAY == 15 ];
then
echo is the same
fi
However when I am trying to execute the script, I get:
./sedtest2.sh[6]: ==: A test command parameter is not valid.
I believe it is something wrong in my comparison statement.
You can find out how comparisons work in the man page of "test" ("man test").
The opening square bracket ("[") is in fact just an alias or link for "/usr/bin/test", to make shell code more readable:
if [ "$x" = "a" ] ; then
and
if /usr/bin/test "$x" = "a" ; then
is basically the same, the former is just "more natural" to read than the latter. "if" just takes the return code of the following command and "test" returns "0" when the comparison is true, otherwise it returns "1". The following would also work:
if 0 ; then
or
if 1 ; then
The first one would always execute the "then"-branch, the second one always the "else"-branch..