0

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

EJK
  • 12,332
  • 3
  • 38
  • 55
vignesh
  • 1
  • 3

2 Answers2

1

[[ 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 [[.

Jörg W Mittag
  • 363,080
  • 75
  • 446
  • 653
  • Got it thanks. i will check – vignesh Apr 28 '22 at 07:22
  • can you help me to provide the correct document for syntax. i have given single square bracket build successfully – vignesh Apr 28 '22 at 07:31
  • suppose if i need to add a relational operator in the IF condition, need a document to follow syntax. kindly provide me the link for docuemnt – vignesh Apr 28 '22 at 07:32
  • 1
    If you have a question, please post a question, not a comment. However, note that asking for resources, documents, links, etc. is off-topic. That's what search engines are for. – Jörg W Mittag Apr 28 '22 at 08:35
1

[[ 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.

user1934428
  • 19,864
  • 7
  • 42
  • 87