问题
I am trying to run aws create lambda function. It goes as follows -
eval $(aws lambda create-function \
--function-name $FUNCTION_NAME \
--runtime $RUNTIME \
--role $ROLE \
--handler $HANDLER \
--region $REGION \
--zip-file $ZIP_FILE \
--profile $PROFILE \
--environment $env_variables)
All the variables come from command line. It is failing for env_variables. This gets constructed as -
env_variables="Variables={INPUT=${DAYS}}"
where DAYS is actually "20 days"
How can I avoid this space and pass my command successfully.
回答1:
The value needs to be wrapped in quotes, try this:
env_variables="Variables=\"{INPUT=${DAYS}}\""
回答2:
Finally following worked -
env_variables="\"Variables\":{\"INPUT\":\"${DAYS}\"}"
lambda_create_command="aws lambda create-function --function-name $FUNCTION_NAME --runtime $RUNTIME --role $ROLE --handler $HANDLER --region $REGION --zip-file $ZIP_FILE --profile $PROFILE --environment '$env_variables'"
echo "Executing command : $lambda_create_command"
eval $lambda_create_command
Important points -
- Quotes in
env_variables
- Use of
eval
- Single quote in command string i.e
$env_variables
Reference - https://gist.github.com/andywirv/f312d561c9702522f6d4ede1fe2750bd
Complete working code :https://gist.github.com/aniket91/19492b32f570ece202718153661b1823
来源:https://stackoverflow.com/questions/47111075/bash-script-failing-with-unknown-option-due-to-space-in-argument