The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
why the date format dont work in crontab p4cldba UNIX for Advanced & Expert Users 7 06-30-2008 08:09 PM
date issue-find prevoius date in a patricular format bsandeep_80 UNIX for Advanced & Expert Users 3 11-15-2007 08:42 PM
convert mmddyy date format to ccyyddd format?? Bhups Shell Programming and Scripting 2 09-27-2006 11:30 PM
Date format - Shell scripting gurus please help geomonap Shell Programming and Scripting 3 02-02-2006 05:15 AM
convert date in lilian format for shell (AIX) chocolate AIX 2 11-09-2004 04:48 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-10-2008
mrx1350 mrx1350 is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 23
Date Format Does not work in Shell

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
  #2 (permalink)  
Old 10-10-2008
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,310

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:

Code:
NOW=`date +%Y%m%d`
... but you should figure out why it is not using ksh.

How are you calling the script?
  #3 (permalink)  
Old 10-10-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink I don't see anything wrong

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??

Code:
> 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
>
  #4 (permalink)  
Old 10-10-2008
mrx1350 mrx1350 is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 23
Quote:
Originally Posted by cfajohnson View Post

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:

Code:
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.
  #5 (permalink)  
Old 10-10-2008
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,310

By calling it with sh, you are using a non-standard shell (are you on Solaris?) rather than ksh.
  #6 (permalink)  
Old 10-10-2008
mrx1350 mrx1350 is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 23
Quote:
Originally Posted by cfajohnson View Post

By calling it with sh, you are using a non-standard shell (are you on Solaris?) rather than ksh.
yes in on a solaris environment
  #7 (permalink)  
Old 10-10-2008
mrx1350 mrx1350 is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 23
Quote:
Originally Posted by cfajohnson View Post

By calling it with sh, you are using a non-standard shell (are you on Solaris?) rather than ksh.
if i don't use the sh infront of the script, it does not run
Sponsored Links
Closed Thread

Bookmarks

Tags
date

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 01:19 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0