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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IF-FI in ksh

Status
Not open for further replies.

tbohon

Programmer
Apr 20, 2000
293
US
Given the following code:

if (($# == 0))
then
echo ERROR - no command line argument
echo
echo Usage: dailyrec.ksh MMDD
echo where MMDD is the month and day of the desired files
echo

else

...

fi


The first time each login session I run this script without a command line argument it gives the error message above. However, when I try to run it again without a command line argument, it skips this portion, follows the 'else' path, and gets really confused ... the command line argument gives it part of a file name it's looking for. I can log out and back in again and it'll show the error only on the first time it's run.

Tnx.

 
UPDATE: In checking further, it's apparently remembering the arguments from the previous run - the line it shows when it can't find the file has the older value in it - so guess the question is how do I, at the very end of the 'else' branch in the script, make it 'forget' the value? I've tried the command

set ""

but it didn't seem to work.

Thanks again.
 
How are you calling this script ?
I guess you source it (ie using the dot command).

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Yes, it's sourced ... I use . dailyrec.ksh from the command line.

Note that, once I've bullet-proofed it as much as possible, I'll be putting it into crontab to run automatically every day ... but that's another issue.
 
Why are you sourcing it ?
Why not simply executing it, like this ?
dailyrec.ksh $(date '+%m%d')

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Habit ... all of the scripts (developed by others on this system) source the commands so that's what I've been doing.

I'll give your suggestion a shot and see if it cures the problem.

Tnx.
 
Nope ... gave me execution denied. The rights, etc. that we use on this server are screwy at times so let me talk with our SA and see if he has an idea.

Thanks again for all the help - I really appreciate it.
 
You may try this:
ksh dailyrec.ksh 1220

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Also consider using...
[tt]
shift $#
[/tt]
... to unset the parameters.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top