# Shell: while loop wont work in my freeBSD, any idea?



## vaclinux (Feb 16, 2009)

Dear,
Hope you can try 

```
opt="x"
        while [[ $opt != "y" && $opt != "n" ]]
        do
         echo "Do you want to continoue(y/n)"
         read opt 
        done
```
and help why i got 


> [[: not found


after executing the shell script in my freebsd 6.2, it seem the "[[" assume as a command.

Btw, this script is working in my linux os(fedora10)


----------



## ale (Feb 16, 2009)

That's because this is a bash script.


----------



## vermaden (Feb 16, 2009)

You use strict bash(1) syntax, which is not POSIX compatible (works only @ bash), use strict POSIX sh(1) syntax, even on Linux, then you will have much less problems porting your scripts to other operating systems, here is a code that does the same and works the same, even under POSIX sh(1):


```
OPT="x"
while [ ${OPT} != "y" -a ${OPT} != "n" ]
do
  echo -n "Do you want to continue (y/n): "
  read OPT
done
```


----------



## vaclinux (Feb 16, 2009)

It is working now,
I need to understand more about POSIX standard,
Thanks,


----------



## vermaden (Feb 16, 2009)

vaclinux said:
			
		

> It is working now,
> I need to understand more about POSIX standard,
> Thanks,



You are welcome, generally if it works under #!/bin/sh under FreeBSD/OpenBSD/NetBSD then its POSIX standart, that do not applies to #!/bin/sh at Linux, since there 99% of the times /bin/sh --> /bin/bash (is just a symlink).


----------



## Brandybuck (Feb 16, 2009)

Bash is not the Bourne (POSIX) shell. It add a whole bunch of really nice features, and is mostly compatible with sh. But not quite. That wouldn't be a problem, except that a few Linux distros decided to symlink bash to sh. That works fine under those Linux distros, but the scripts can break elsewhere if they have bash-isms in them.


----------



## graudeejs (Feb 16, 2009)

why do they use bash, when there is mksh ?
I love mksh, so far i can do in console anything that i could do in #!/bin/sh.


----------



## vermaden (Feb 16, 2009)

killasmurf86 said:
			
		

> why do they use bash, when there is mksh ?
> I love mksh, so far i can do in console anything that i could do in #!/bin/sh.



mksh is designed for INTERACTIVE use, while /bin/sh only to be POSIX compatible without ANY interactive enhaecements like completion and so, thus /bin/sh is a lot better then mksh as system shell for scripts.


----------

