Re: Newbie Scripting Variable Question In article <1155069925.073315.70250@m73g2000cwd.googlegroups. com>, dawaves <dawaves@gmail.com> wrote:
> Why does this not work?
>
> PDAY=echo `cal $PMONTH $PYEAR`|awk '{print $NF}'
>
> I've defined the PMONTH value as the previous month and the PYEAR value
> as teh previous year.
If you want to do evaluate-and-substitute for a variable, you need to do
it something like this:
FOO=`commands to execute`
Basically, you were missing that ` ` in the right place so it didn't
evaluate the expression. Even if you had done it as:
PDAY=`echo `cal $PMONTH ...
It'd still have had failed because shell would have seen more than two
backquotes and gotten confused about how to parse it properly.
One way to do it if you want to do it as one line:
PDAY=`cal $PMONTH $PYEAR|tail -1|awk '{print $NF}'`
-Dan |