0

I declare a temporary file

    TEMPFILE="$(mktemp)"

Then I have an awk statement fill it with an output... Next step, I have another AWK statement take out particular field to put into an array... this is 'crapping out'

DATES = ($(awk -F'/' '{print $2}' '${TEMPFILE}'))

I'm also parsing out into a separate array using a CUT (not sure if it's working either)

IPS = ($(cut -f2 $(TEMPFILE)))

I'm getting the error:

Script12.sh: line 36: syntax error near unexpected token `('

Script12.sh: line 36: `DATES = ($(awk -F'/' '{print $2}' '${TEMPFILE}'))'*

3 Answers 3

3

The shell is space-sensitive. The shell syntax for assignment is

var1=[word1] ...

where the [] indicates an optional part, and ... repetition.

Note: no blanks around the = sign.

Then, there is no parameter expansion (replacing $var with its value) inside single quotes. Use double quotes:

DATES=($(awk -F/ '{print $2}' "${TEMPFILE}"))
Sign up to request clarification or add additional context in comments.

1 Comment

Note that while spaces are forbidden around the = in an assignment, they're required in a test. E.g. if [ "$foo" = "$bar" ] does what you expect, while if [ "$foo"="$bar" ] does something completely different (and useless). And if ["$foo"="$bar"] will get you a command not found error...
3

Don't use blanks for variable assignment in BASH. There should be no blanks around the = sign

1 Comment

@TimEagle I'd like to. But Jens has made it much clearer than me. I thus voted hime up :-)
2

You can't put spaces around assignments in shell and you need to change single to double quotes around your shell variable when used in your awk command line, i.e. "$TEMPFILE" not '${TEMPFILE}' and then not try to execute that variable on your cut command line (think about what $(TEMPFILE) means).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.