Re: Newbie Scripting Variable Question




dawaves wrote:
Wow all great replies...
Dan Foster: I figured it out exactly how you had it...thanks

Thanks so much guys...

How about this one....


How do I make a variable that I have, let's say it's, "1", into "01".
Or "8" into "08"?

I've tried using 'expr' to add "0" or "00" and those didn't work. Any
suggestions?

Thanks!


steven_nospam at Yahoo! Canada wrote:
dawaves wrote:
Why does this not work?

PDAY=echo `cal $PMONTH $PYEAR`|awk '{print $NF}'


A lot of scripters use the single back quotes (`) to indicate a command
to be executed. When I first started out I found it very confusing at
times to see all the different quotes on a line, since you could have
various sets of ", ', and ` on the same line and try to track which are
for what...

You may want to try the following instead. You can use the $(command)
syntax to indicate that everything between the brackets should be
translated and returned to that line. For example:

PDAY=$(cal ${PMONTH} ${PYEAR} | awk '{print $NF}')

Reading this is just like math class. You do the work inside the ( )
first. So what happens is the calendar is produced, and the output is
used as input to the awk command. You then take the results of that and
assign it to PDAY.

By doing it this way, you can test what you are expecting to get on a
command line, then cut and paste the entire line and wrap it in
brackets and you should get the same results assigned to a variable.

Another way to do this is:

cal ${PMONTH} ${PYEAR} | awk '{print $NF}' | read PDAY

The cal is evauated, the output used as input for awk, and then the awk
output is used as input for the read statement to assign a value to
PDAY.

In UNIX, there are almost always 5 ways to accomplish the same goal.
You may wan tto get a copy of the O'Reilly and Associates series of
books....Good examples and well written, they help a lot. Another one
is the Korn Shell by (oddly enough) David Korn.

Steve


# typeset -Z2 abc
# abc=1
# echo $abc
01

.



Relevant Pages

  • Re: Newbie Scripting Variable Question
    ... A lot of scripters use the single back quotes to indicate a command ... assign it to PDAY. ... The cal is evauated, the output used as input for awk, and then the awk ... is the Korn Shell by David Korn. ...
    (comp.unix.aix)
  • Re: Newbie Scripting Variable Question
    ... A lot of scripters use the single back quotes to indicate a command ... The cal is evauated, the output used as input for awk, and then the awk ... is the Korn Shell by David Korn. ...
    (comp.unix.aix)
  • Re: Removing lines from a plain text file
    ... Apparently there is no simple command. ... > and put prune in a cron job. ... > size by removing the excess from the beginning of the file. ... date from the past and use awk to search through the file for it and discard ...
    (comp.unix.sco.misc)
  • Re: Running a job in AIX
    ... command to show what is in the queue, ... we create a short script that sets our environment ... into an sql table, then runs an sql procedure to process the data in ... I would recommend that you get a copy of "Learning the Korn Shell" from ...
    (comp.unix.aix)
  • Re: Running a job in AIX
    ... command to show what is in the queue, ... we create a short script that sets our environment ... into an sql table, then runs an sql procedure to process the data in ... I would recommend that you get a copy of "Learning the Korn Shell" from ...
    (comp.unix.aix)