0

I am getting errors when running this bash script. I have checked in all manuals, it looks okay to me?

Help appreciated.

  #!/bin/sh
  HOME=/var/www
  sleep 20
  echo 'running' > $HOME/script-1-output.txt
  if  (-f $HOME/script-2-output.txt )
    echo 'script-2 has run' >> $HOME/script-1-output.txt
  else
    echo 'script-2 has not run' >> $HOME/script-1-output.txt
  fi
  if  (-f $HOME/script-3-output.txt)
    echo 'script-3 has run' >> $HOME/script-1-output.txt
  else
    echo 'script-3 has not run' >> $HOME/script-1-output.txt
  fi
4

1 回答 1

2

In bash, if conditions are wrapped between [] not (). There should always be space between condition and square brackets. And you need then in if-then-else-fi syntax.

if [ -f file.txt ]; then
    echo "yes"
else
    echo "no"
fi
于 2013-09-10T23:39:22.000 回答