This is my code:
#!/bin/bash
cat input$1 | ./prog$1 > output$1 && if[ "$2" != "" ]; diff output$1 expected$1;
This then happens:
$ ./run.sh
./run.sh: line 2: if[ no != ]: command not found
$
I thought that I could run if statements on one line? is that what the problem is?
it turns out that there needs to be a space between the
ifand the[. Also, I put in thethenandfikeywords.The following worked.
EDIT:
as commented below (and in another answer), this can elegantly be shortened to:
in which case I don’t even have to remember any of the rules about how to use the
ifconstruct 🙂