I have a script that works curl. I want to be able to optionally add a parameter -Hif the row is not empty. What complex are citation levels and spaces.
caption="Test Caption"
if [ "${caption}" != "" ]; then
CAPT=-H "X-Caption: ${caption}"
fi
curl -A "$UA" -H "Content-MD5: $MD5" -H "X-SessionID: $SID" -H "X-Version: 1" $CAPT http://upload.example.com/$FN
The idea is that the CAPT variable is either empty or contains the desired -H header in the same way as others, for example, -H "X-Caption: Test Caption"
The problem is that at startup it interprets the assignment as a command to execute:
$bash -x -v test.sh
+ '[' 'Test caption' '!=' '' ']'
+ CAPT=-H
+ 'X-Caption: Test caption'
./test.sh: line 273: X-Caption: Test caption: command not found
I tried to reset the IFS before the code, but that did not affect.
source
share