0

This is my demo.sh file

#!/bin/bash
if [[ $(ls -A) ]]; then
echo "there are files"
else
echo "no files found"
fi

but when i run this i get output as

    demo.sh: 3: demo.sh: [[: not found
    no files found

but there is some file on this directory

marked as duplicate by muru bash Sep 15 '17 at 13:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    [[ like shopt is a bash feature, so you should use a shebang in your script or run it with bash – muru Sep 15 '17 at 13:46
  • 'shebang' == a first line in the script with the content #!/bin/bash – sudodus Sep 15 '17 at 13:48
  • @muru even by adding #!/bin/bash .. m getting same error – Gaurav Singh Sep 15 '17 at 13:53
  • @GauravSingh how are you running the script? – muru Sep 15 '17 at 13:53
  • 3
    See askubuntu.com/questions/22910/… about that you should run with bash demo.sh or ./demo.sh – muru Sep 15 '17 at 13:56