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

set command and positional parameters

Status
Not open for further replies.

djessi

IS-IT--Management
Dec 29, 2006
93
CM
Hi all,
I am writing a shell script with positionnal parameters
and a set command (set `date`), the set command resets the positionnal parameters (taking the value of fields of date command)so that the arguments used when I execute my shell script are changed. How can I call them back inside my shell script (ksh).
Thanks for help
Consty
 
Why don't you store them in an array for example!?

Code:
i=0
set *
while true
do
if [[ $# -eq 0 ]]
then
arr[i] = $1
shift
((i = i + 1))
done

Haven't tested the above to be honest!

Regards,
Khalid
 
I don't think you want that "set *" (which I think was meant to be "set $*") in khalidaaa's code. It'll create problems if you have any quoted parameters with embedded spaces, or more correctly any embedded field separators. Just remove it, and that code to store params in an array should work.

If you're using the "set `date`" to pull out individual parts of the date, you could avoid overwriting the command line parameters altogether by using format strings to get the information you need.

Example: [tt]dayabbrev=`date +"%a"`[/tt] will assign the abbreviated weekday name (i.e. Thu) to [tt]dayabbrev[/tt].

- Rod


IBM Certified Advanced Technical Expert pSeries and AIX 5L
CompTIA Linux+
CompTIA Security+

Wish you could view posts with a fixed font? Got Firefox & Greasemonkey? Give yourself the option.
 
imho syntax is wrong, should be

set -- `date`


HTH,

p5wizard
 
OMG :)

Thanks Rod for the correction :) it must be mistyped!

Regards,
Khalid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top