mrx1350
October 10, 2008, 11:03am
1
I'm am able to format the date in the unix prompt using NOW=$(date +"%d%m%y"). However, when i put the same format into a shell script, it errors out with the followign.
sintax error on line 4: `NOW=$' unexpected.
#!/bin/ksh
EXP_LOC=/u02/oradata/exports
NOW=$(date +"%d%m%y")
echo $NOW
~
~
~
~
~
~
~
~
~
~
"test" 13 lines, 363 characters
That looks as if it's being executed by a non-standard shell rather than by ksh. You can use the old-fashioned form of command substitution:
NOW=`date +%Y%m%d`
... but you should figure out why it is not using ksh.
How are you calling the script?
joeyg
October 10, 2008, 11:26am
3
Can you try a simpler command? Perhaps just setting with date like in my second assignment in my script. Maybe your system does not like part of the date options??
> cat date_scr
#!/bin/ksh
EXP_LOC=/u02/oradata/exports
NOW=$(date +"%d%m%y")
echo $NOW
NOW2=$(date)
echo $NOW2
> ksh date_scr
101008
Fri Oct 10 08:24:26 PDT 2008
>
mrx1350
October 10, 2008, 11:30am
4
cfajohnson:
That looks as if it's being executed by a non-standard shell rather than by ksh. You can use the old-fashioned form of command substitution:
NOW=`date +%Y%m%d`
... but you should figure out why it is not using ksh.
How are you calling the script?
i was calling the shell using the sh before the script. for instance sh file.sh.
I tried the other way you suggested and worked fine. thanks.
By calling it with sh, you are using a non-standard shell (are you on Solaris?) rather than ksh.
mrx1350
October 10, 2008, 11:44am
6
yes in on a solaris environment
mrx1350
October 10, 2008, 11:46am
7
if i don't use the sh infront of the script, it does not run
joeyg
October 10, 2008, 11:48am
8
Then change the syntax to the following:
NOW=`date +"%d%m%y"`
Then either put it in a directory in your PATH or call it with an explicit path, e.g., ./myscript, and make sure it is executable.
Or call it with ksh instead of sh.