From: Ed Morton on
On May 26, 7:12 am, kielhd <kie...(a)freenet.de> wrote:
> Hi NG,
>
> I am writing a script that is supposed to run on different UNIX-
> derivates. It runs OK on AIX, HP-UX and Linux.
>
> At the moment, I am implementing the SunOS part. At SunOS I came over
> a problem, where I need your help.
>
> The script consists of a seperate section for each UNIX-derivate and a
> common part, that is used by *ALL*
>  UNIX-derivates. I have got a problem in the common part.
>
> In this common part I am using the command 'awk' to do some text
> manipulations:
> ...
> awk -v c1schwell1...
> ...
>
> In SunOS, this command needs to be replaced by:
> ...
> /usr/xpg4/bin/awk -v c1schwell1...
> ...
>
> My question:
> Is it possible to replace a command depending on the name of the
> operating system?
>
> To put my question in a different way:
> Is it possible to tell my script to use the command '/usr/xpg4/bin/
> awk' instead of the command 'awk' if it is running on SunOS?

I wouldn't worry about testing the OS but instead just focus the
script on finding a working awk in your preferred order. e.g.:

AWK=""
order="
/usr/xpg4/bin/awk
/usr/bin/nawk
$(where nawk)
$(where gawk)
$(where awk)
"
for awk in $order; do
if [ $( "$awk" -v x=1 'BEGIN{print x; exit}' ) ]; then
AWK="$awk"
break
fi
done

if [ -z "$AWK" ]; then
echo "ERROR: Couldn't find a working awk; exiting." >&2
exit 1
fi

After all, all you really care about is finding a working awk so why
restrict yourself to just handling a specifc Solaris issue?

Regards,

Ed.