porting script from AIX 4.2 ksh to Linux ksh/bash

Interresting one. I am experimenting with scripts on unix. I wrote a basic script to check if the first command line parameter starts with gr.

--------------
firstparm=$1
firstparm=${firstparm:?"missing"}
if [[ $firstparm = gr* ]] ; then
  echo The parameter starts with gr
else
  echo The parameter does NOT starts with gr
fi
--------------

On AIX this works fine, but when I try to run this in Linux Redhat 6.0 bash (v 1.14.7) or ksh (PD v5.2.14) I get the error:
[[: command not found.

Why?
Any references will be welcome.
r__bAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ahoffmannCommented:
this is a know bug in pdksh version < 5.2.4
see http://www.cs.mun.ca/~michael/pdksh/
0
r__bAuthor Commented:
Fair, but what about bash. I have to admit that I am not an expert in bash scripting and is not sure if it should be working.

In both cases, what would work?
0
ahoffmannCommented:
[[ is not a bash command (man bash), bash even has no similar command, you only can workaround using bash's
   case $firstname in ...
builtin command

bash is not compatible to ksh, just to sh,
Only scripts using bare sh syntax are guaranteed to run in ksh, pdksh and bash. But be prepared for dragons when you use bash.

I highli recommend that you use the magic line in the script to tell the calling shell which interpreter/program to use.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
r__bAuthor Commented:
Thanks A Hoffmann (I assume)

Guess it is back to the man pages for me. I know it will not work, but I am not experienced enough to know what would work.

muru_za
0
ahoffmannCommented:
> but I am not experienced enough  to know what would work.
man sh
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.