unix中变量之间的比较问题

Problem comparing between variable in unix

我在将文件的第一行与我发送的参数进行比较时遇到问题,我该如何解决?

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

在您引用的“问题行”中,您正在寻找 command substitution,从而允许命令的输出替换命令本身。

你的行应该是:

if [[ $(head -1 "$file") == "" ]]