Home > Net >  Problem comparing between variable in unix
Problem comparing between variable in unix

Time:01-17

I have a problem where i compare the first line of the file to a paremeter i send, how can i fix it?

./lab12.sh lyrics "Yesterday"
if [[ "$1" == "lyrics" ]]
then
for file in /tmp/beatles/*.txt ; do
          if [[ head -1 $file == "$2" ]] //problem here !
          then
          echo cat | tail  3 $file
          fi
          done 
          fi
echo "Error - Song name not found"
fi

CodePudding user response:

At the "problem line" you cited, you are looking for command substitution, thereby allowing the output of the command to replace the command itself.

Your line should read:

if [[ $(head -1 "$file") == "$2" ]]
  •  Tags:  
  • Related