when i execute the script it gives error as [[: not found
6.txt file has following values 1.7\n 1.8\n 1.5\n1.4\n 1.9\n 33.5
#! /bin/bash
INPUT=6.txt while read a ; do
x="$a"
echo value of x : $x
if [[ $a >= 1.7 ]];
then
echo "test passed"
else
echo "test failed"
# echo else block a :$a
fi
done<"$INPUT"
Error
./test3.sh
value of x : 1.7 ./test3.sh: 18: [[: not found test failed value of x : 1.8 ./test3.sh: 18: [[: not found test failed value of x : 1.5 ./test3.sh: 18: [[: not found test failed value of x : 1.4 ./test3.sh: 18: [[: not found test failed value of x : 1.9 ./test3.sh: 18: [[: not found test failed value of x : 33.5 ./test3.sh: 18: [[: not found test failed
i am using busybox tiny version of unix
BusyBox v1.01 (2021.12.29-16:10 0000) Built-in shell (ash) Enter 'help' for a list of built-in commands.
kinldy help me to solve this error
CodePudding user response:
[[
is a feature of the KornShell (ksh
). You are using the Almquist Shell (ash
), more precisely, Busybox's fork of dash
, the Debian Almquist Shell, which does not have this feature.
More precisely, in BusyBox support for [[
is optional and controlled by a compile-time option. You have compiled your BusyBox without support for [[
. If you want to use [[
in BusyBox, you need to configure and re-compile it with support for [[
.
CodePudding user response:
[[
is present in bash, ksh and zsh, not in POSIX shell, but even then, you can not do comparision with floats within [[ ... ]]
. At least zsh has float arithmetic, if you do it properly. I suggest to change your script to
if (( a >= 1.7 ))
and execute the script by
zsh test3.sh
At least this error should go away.