Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assigning a variable

Status
Not open for further replies.

smm4301

Programmer
Aug 1, 2003
5
US
Not sure if this is posted to the right place.
I have a script that is trying to get the day and month of an entered file name. I found this code which will print it out:

#!/bin/ksh

month=`date +%m`
day=`date +%d`

ls -l $FILE | nawk -v month=${month} '
{ printf("%s\n", index($(NF-3), ":") ? month : $(NF-3));
}
'

ls -l $FILE | nawk -v day=${day} '
{ printf("%s\n", index($(NF-2), ":") ? day : $(NF-2));
}
'


Is there anyway to store the printed answer in a variable instead of writing it to the sreeen?

Thanks in advance,
Steph
 
> Is there anyway to store the printed answer in a variable instead of writing it to the sreeen?
Just put the command in back-ticks, like you did with the date command

Code:
var=`ls -l $FILE | nawk -v month=${month} '
 { printf("%s\n", index($(NF-3), ":") ? month : $(NF-3));
 }'`
 
Try

[red]mm=`[/red]ls -l $FILE | nawk -v month=${month} '
{ printf("%s\n", index($(NF-3), ":") ? month : $(NF-3));
}
'[red]`[/red]

[red]da=`[/red]ls -l $FILE | nawk -v day=${day} '
{ printf("%s\n", index($(NF-2), ":") ? day : $(NF-2));
}
'[red]`[/red]


CaKiwi

"I love mankind, it's people I can't stand" - Linus Van Pelt
 
It worked! I tried everything but that it seems like :)

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top