Date Format Does not work in Shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Date Format Does not work in Shell
# 1  
Old 10-10-2008
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  
Old 10-10-2008

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  
Old 10-10-2008
Hammer & Screwdriver 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  
Old 10-10-2008
Quote:
Originally Posted by 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:

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  
Old 10-10-2008

By calling it with sh, you are using a non-standard shell (are you on Solaris?) rather than ksh.
# 6  
Old 10-10-2008
Quote:
Originally Posted by cfajohnson

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  
Old 10-10-2008
Quote:
Originally Posted by cfajohnson

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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Rename all Files in a UNIX Directory from one date format to another date format

Hi Unix Gurus, I would like to rename several files in a Unix Directory . The filenames can have more than 1 underscore ( _ ) and the last underscore is always followed by a date in the format mmddyyyy. The Extension of the files can be .txt or .pdf or .xls etc and is case insensitive ie... (1 Reply)
Discussion started by: pchegoor
1 Replies

2. Shell Programming and Scripting

Change date format in shell script

Plz help me To display date in the mm/dd/yyyy. Eg. if date is 28-09-2012 the output of the shell script should be date 09/28/2012. (1 Reply)
Discussion started by: shivasaini
1 Replies

3. UNIX for Dummies Questions & Answers

Shell Scripts - shows today’s date and time in a better format than ‘date’ (Uses positional paramete

Hello, I am trying to show today's date and time in a better format than ‘date' (Using positional parameters). I found a command mktime and am wondering if this is the best command to use or will this also show me the time elapse since 1/30/70? Any help would be greatly appreciated, Thanks... (3 Replies)
Discussion started by: citizencro
3 Replies

4. Shell Programming and Scripting

How to increment a user defined date value in the DATE format itself using shell script?

I need to increment a date value through shell script. Input value consist of start date and end date in DATE format of unix. For eg. I need increment a date value of 1/1/09 to 31/12/09 i.e for a whole yr. The output must look like 1/1/09 2/2/09 . . . 31/1/09 . . 1/2/09 . 28/2/09... (1 Reply)
Discussion started by: sunil087
1 Replies

5. Shell Programming and Scripting

Convertion of Date Format using SQL query in a shell script

When I write Select date_field from TableA fetch first row only I am getting the output as 09/25/2009. I want to get the output in the below format 2009-09-25 i.e., MM-DD-YYYY. Please help (7 Replies)
Discussion started by: dinesh1985
7 Replies

6. UNIX for Dummies Questions & Answers

Changing from Excel date format to MySQL date format

I have a list of dates in the following format: mm/dd/yyyy and want to change these to the MySQL standard format: yyyy-mm-dd. The dates in the original file may or may not be zero padded, so April is sometimes "04" and other times simply "4". This is what I use to change the format: sed -i '' -e... (2 Replies)
Discussion started by: figaro
2 Replies

7. Shell Programming and Scripting

convert date format to mysql date format in log file

I have a comma delimited log file which has the date as MM/DD/YY in the 2nd column, and HH:MM:SS in the 3rd column. I need to change the date format to YYYY-MM-DD and merge it with the the time HH:MM:SS. How will I got about this? Sample input 02/27/09,23:52:31 02/27/09,23:52:52... (3 Replies)
Discussion started by: hazno
3 Replies

8. UNIX for Advanced & Expert Users

why the date format dont work in crontab

Hi I tried to put a cron job which pipes the logfile appended to date +%d but it didnt work . anyone know how to make this happen thanks in advance -prasad (7 Replies)
Discussion started by: p4cldba
7 Replies

9. Shell Programming and Scripting

Date format - Shell scripting gurus please help

Guys: I have the following script (from this forum) to calculate yesterdays date. However the format of the date that is output is yyyymd if the resultant date is single digit or the resultant month is a single digit month ( 01 - 09 ). How can I get the output to show the date in the following... (3 Replies)
Discussion started by: geomonap
3 Replies

10. AIX

convert date in lilian format for shell (AIX)

hello ! can so help me ? i'm writting a shell srcipt ( UNIX AIX) and I'd like to convert a date as 20041108 in lilian format. thanks so much (2 Replies)
Discussion started by: chocolate
2 Replies
Login or Register to Ask a Question