View Full Version : [Solved] Shell: while loop wont work in my freeBSD, any idea?
vaclinux
February 16th, 2009, 06:27
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
February 16th, 2009, 07:25
That's because this is a bash script.
vermaden
February 16th, 2009, 07:28
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
February 16th, 2009, 08:14
It is working now,
I need to understand more about POSIX standard,
Thanks,
vermaden
February 16th, 2009, 08:57
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
February 16th, 2009, 09:06
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
February 16th, 2009, 09:10
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
February 16th, 2009, 09:35
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.
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.