I'm trying to use an if [grep] using the exit value to trigger it
to test, from the command line
$ ls ~/dir | grep txt
$ echo $?
0
However when i use it in an if statement in a script, i.e.
if [ ls /some/dir | grep -q pattern ]; then
echo y
fi
It says
line 1: [ missing `]' (the line the if statement was written on)
Why is this happening and is there a way to fix it?