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.

if [[ $firstparm = gr* ]] ; then
  echo The parameter starts with gr
  echo The parameter does NOT starts with gr

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.

Any references will be welcome.
Who is Participating?
ahoffmannConnect With a Mentor Commented:
[[ 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.
this is a know bug in pdksh version < 5.2.4
see http://www.cs.mun.ca/~michael/pdksh/
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?
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.

> but I am not experienced enough  to know what would work.
man sh
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.