I am new to bash scripts. I would like to compare the number of files I have in another directory using ls
. And then I need to compare the number of files there with a variable I have.
if [ (cd reports_dir/ && ls) | wc -gt $MAXIMUM_REPORTS ]; then
echo hello
fi
This code gives the errors:
./monitor.sh: line 70: syntax error near unexpected token `cd'
./monitor.sh: line 70: ` if [(cd reports_dir/ && ls) | wc -gt $MAXIMUM_REPORTS]; then'
I have idea why cd
is unexpected. The command (cd reports_dir/ && ls) | wc
works when I run it in the terminal.
This command would be running in a while
loop so it will be called repeatedly. Thus I cannot actually cd into the directory as it attempts to cd
more than once, resulting in an error.