0

In a bash script I read a file aa001 and return the first value. When the first value is equal to 1, return a message like ok, on the terminal

#!/bin/bash  
varReprise=`head -n 1 aa001`
echo $varReprise
un=1
if [`$varReprise` = `$un`]
 then
   echo " OK "
else 
   echo "not Ok"
fi

But I have the following error when I run the script:

./test: ligne 5: 1 : command not found 
./test: ligne 5: [: « ] » command not found 
gniourf_gniourf
  • 44,650
  • 9
  • 93
  • 104
daday001
  • 91
  • 1
  • 9
  • 3
    remove the backticks and add spaces : `if [ $varReprise = $un ]` – amdixon Sep 29 '15 at 10:53
  • 1
    As a remark: you should quote all your variable expansions: `echo "$varReprise"`, and `if [ "$varReprise = "$un" ]` or even use the more robust `[[` keyword: `if [[ "$varReprise" = "$un" ]]`. A second remark: you don't need an external process to read the first line of a file. Instead of `varReprise=\`head -n 1 aa001\``, consider using `read -r varReprise < aa001`. – gniourf_gniourf Sep 29 '15 at 11:28

0 Answers0