1847253 Members
2858 Online
110263 Solutions
New Discussion

Problem With Script

 
Shannon_1
Occasional Advisor

Problem With Script

OK, I'm in the beginning stages of learning
how to script. I'm using the Bourne shell
and can't seem to get my variables to accept values other than strings.

Example:

#!/bin/sh
day='date+%a'
echo $day

Result: date+%a

What am I doing wrong?

Thanks.
4 REPLIES 4
A. Clay Stephenson
Acclaimed Contributor

Re: Problem With Script

You should be using 'backticks' the ` rather than the single quote '

The better answer is to use the POSIX shell convention
DAY=$(date '+%a')

If it ain't broke, I can fix that.
Sridhar Bhaskarla
Honored Contributor

Re: Problem With Script

There should be a space between date and +.
And make sure you are using the command substitution quotes.

day=`date +%a`
echo $day

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Sachin Patel
Honored Contributor

Re: Problem With Script

Hi Shannon,
DAY=`date +%d`

few more variable initiliztion

HOSTNAME=`uname -n`
FILE="/usr/local/etc/filename"
RUNNING=`ps -e |grep sleep |wc -l`

system is down.
RESULT=`/etc/ping system1 64 3 | grep "packet loss" | sed 's/%//g' | awk '{print
$7}'`
if [ $RESULT -ge 100 ]; then
mailx -s "system1 is down `date`" sachin < /dev/null
exit
fi

arithmatic.
total_min=`expr ${SECONDS} / 60`

Sachin

Is photography a hobby or another way to spend $
SHABU KHAN
Trusted Contributor

Re: Problem With Script

Shanon,

I would normally use:

#!/bin/sh
day=`date "+%a"`
echo $day

Thu

Thanks,
Shabu