Execute command and compare it in a if statement
问题 I am using bash scripting to check whether two specific directories are containing some specific number of files. lets assume 20. Is it possible to check it in a line inside a if statement? #!/bin/bash if [ [ls /path/to/dir1 | wc -l ] != 20 || [ ls /path/to/dir2 | wc -l ] != 50 ]; then echo "do this!" elif echo "do that!" fi 回答1: The syntax is incorrect: if [[ $(ls /path/to/dir1 | wc -l) != 20 || $(ls /path/to/dir2 | wc -l) != 50 ]] then echo "do this!" else echo "do that!" fi (I move the