PDA

View Full Version : expr on SunOS


dove17
04-04-03, 05:17
Hi,
I have this peice of code that does not work on SunOS. Can anyone tell why?

#! /bin/sh
showdate=05042003

echo $showdate
aday="`expr ${showdate:0:2}`"
echo "day is $aday"
exit 0


if i do it from command line like
bash$ >showdate=05042003
bash$ >aday="`expr ${showdate:0:2}`"
bash$ >echo $aday
05

i get correct answer but it does not work in script.

all answers are welcome.

dove17

halkan
04-24-03, 04:23
In your command line example, you are using the "bash" shell. However, in your script you are forcing the script to use "sh" shell by including #!/bin/sh.
Change it to #!/bin/bash (or wherever bash shell is installed on your system) and you should see identical results.