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

shell fails on solaris 5.8 but works on 2.6 1

Status
Not open for further replies.

art15t

MIS
Apr 8, 2002
77
GB
Has anyone experienced problems with shells failing on sol8 when the script passes space separated strings as an argument to a command? The script works fine on Sol2.6

e.g.

# get user description

while [ -z "$COMMENT" ]
do
read -r COMMENT?"Please enter a comment to identify this user > "
done

# if we entered "joe bloggs" as the info and then we do something like....

/usr/sbin/useradd -g other -d /export/home/$LOGIN -s /bin/ksh -c "$COMMENT" -m $LOGIN

The script fails because the comment was not wrapped in quotes but if when I'm prompted for the comment I place the comment inside quotes then it works ok.

I've tried various combinations on wrapping the comment inside the script but it fails on every occasion.

Anyone have a simple answer to this, i think the only thing i haven't tried is echo'ing the string on the command line....will that work?

ART
 
Try putting a...
[tt]
unset IFS
[/tt]
...just before the [tt]read[/tt]. [tt]IFS[/tt] defines the Inter-Field Separator character. If it's set to a space, then entering "joe bloggs" is actually TWO entries to the read, not one.

Hope this helps!
 
You should be able to place the escape character \ before the quotes when you call it. The line should look like this:

/usr/sbin/useradd -g other -d /export/home/$LOGIN -s /bin/ksh -c \"$COMMENT\" -m $LOGIN

Hope this helps out!
 
Thankyou people!

My apologies for not getting back sooner but sambones sorted it with "unset IFS". IFS was set to newline and when the command was executed it got separated into 2 or 3 separate commands which of course were not recognised by the shell.

Thanks once again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top