Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I created this bash script based on answers I found here:

If [[ $(autorep -J jobname | cut -c108-110 | sed -n '/ST/!'p | sed '/^$/d' | sed -n '/_/!'p) == *ST* ]]; then
    echo "Status is Started"
fi

error:

./stj.sh: line 1: syntax error near unexpected token `then'
  1. The command inside the () works if I cut and paste in the terminal, but I get an error when I execute with the if command.
share|improve this question

closed as off-topic by jasonwryan, roaima, cuonglm, G-Man, Anthon Aug 25 at 5:41

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – jasonwryan, roaima, cuonglm, G-Man, Anthon
If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers 2

You indicate that you said If.  bash keywords are case-sensitive; you must use if (lower case).

share|improve this answer

In addition to having a capital if as Scott pointed out, the terminal may require termination of the "then" statement (assuming you are pasting it in on one line).

Try pasting:

if [[ $(autorep -J jobname | cut -c108-110 | sed -n '/ST/!'p | sed '/^$/d' | sed -n '/_/!'p) == *ST* ]]; then echo "Status is Started"; fi

(note the semi-colon before the fi)

share|improve this answer
1  
This is only true if you write it as a one-liner like you did. –  yoonix Aug 24 at 23:10
    
Thanks yoonix I edited my answer clarifying my assumption. –  Klaatu von Schlacker Aug 24 at 23:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.