Bash script failing with unknown option due to space in argument [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite













This question already has an answer here:



  • Why does my shell script choke on whitespace or other special characters?

    4 answers



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.







share|improve this question














marked as duplicate by Gilles shell
Users with the  shell badge can single-handedly close shell questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 4 '17 at 18:50


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 4




    Did you try proper quoting?
    – Ignacio Vazquez-Abrams
    Nov 4 '17 at 13:46










  • I need a string like env_variables="Variables=INPUT=20 days" which means "Variables=INPUT=20 days" is a json sting fed to environment option of the command. I tried DAYS="'45 days'". Does not work.
    – Aniket Thakur
    Nov 4 '17 at 13:55






  • 1




    Please put that update ^^ ^^ ^^ into your question, where it belongs so that everyone can easily find it.
    – roaima
    Nov 4 '17 at 14:32










  • I guess it was quotes after all. Took couple of hour to figure correct combinations.
    – Aniket Thakur
    Nov 4 '17 at 14:39














up vote
0
down vote

favorite













This question already has an answer here:



  • Why does my shell script choke on whitespace or other special characters?

    4 answers



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.







share|improve this question














marked as duplicate by Gilles shell
Users with the  shell badge can single-handedly close shell questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 4 '17 at 18:50


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 4




    Did you try proper quoting?
    – Ignacio Vazquez-Abrams
    Nov 4 '17 at 13:46










  • I need a string like env_variables="Variables=INPUT=20 days" which means "Variables=INPUT=20 days" is a json sting fed to environment option of the command. I tried DAYS="'45 days'". Does not work.
    – Aniket Thakur
    Nov 4 '17 at 13:55






  • 1




    Please put that update ^^ ^^ ^^ into your question, where it belongs so that everyone can easily find it.
    – roaima
    Nov 4 '17 at 14:32










  • I guess it was quotes after all. Took couple of hour to figure correct combinations.
    – Aniket Thakur
    Nov 4 '17 at 14:39












up vote
0
down vote

favorite









up vote
0
down vote

favorite












This question already has an answer here:



  • Why does my shell script choke on whitespace or other special characters?

    4 answers



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.







share|improve this question















This question already has an answer here:



  • Why does my shell script choke on whitespace or other special characters?

    4 answers



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.





This question already has an answer here:



  • Why does my shell script choke on whitespace or other special characters?

    4 answers









share|improve this question













share|improve this question




share|improve this question








edited Nov 4 '17 at 18:50









Gilles

507k12010031532




507k12010031532










asked Nov 4 '17 at 13:45









Aniket Thakur

243111




243111




marked as duplicate by Gilles shell
Users with the  shell badge can single-handedly close shell questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 4 '17 at 18:50


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Gilles shell
Users with the  shell badge can single-handedly close shell questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 4 '17 at 18:50


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









  • 4




    Did you try proper quoting?
    – Ignacio Vazquez-Abrams
    Nov 4 '17 at 13:46










  • I need a string like env_variables="Variables=INPUT=20 days" which means "Variables=INPUT=20 days" is a json sting fed to environment option of the command. I tried DAYS="'45 days'". Does not work.
    – Aniket Thakur
    Nov 4 '17 at 13:55






  • 1




    Please put that update ^^ ^^ ^^ into your question, where it belongs so that everyone can easily find it.
    – roaima
    Nov 4 '17 at 14:32










  • I guess it was quotes after all. Took couple of hour to figure correct combinations.
    – Aniket Thakur
    Nov 4 '17 at 14:39












  • 4




    Did you try proper quoting?
    – Ignacio Vazquez-Abrams
    Nov 4 '17 at 13:46










  • I need a string like env_variables="Variables=INPUT=20 days" which means "Variables=INPUT=20 days" is a json sting fed to environment option of the command. I tried DAYS="'45 days'". Does not work.
    – Aniket Thakur
    Nov 4 '17 at 13:55






  • 1




    Please put that update ^^ ^^ ^^ into your question, where it belongs so that everyone can easily find it.
    – roaima
    Nov 4 '17 at 14:32










  • I guess it was quotes after all. Took couple of hour to figure correct combinations.
    – Aniket Thakur
    Nov 4 '17 at 14:39







4




4




Did you try proper quoting?
– Ignacio Vazquez-Abrams
Nov 4 '17 at 13:46




Did you try proper quoting?
– Ignacio Vazquez-Abrams
Nov 4 '17 at 13:46












I need a string like env_variables="Variables=INPUT=20 days" which means "Variables=INPUT=20 days" is a json sting fed to environment option of the command. I tried DAYS="'45 days'". Does not work.
– Aniket Thakur
Nov 4 '17 at 13:55




I need a string like env_variables="Variables=INPUT=20 days" which means "Variables=INPUT=20 days" is a json sting fed to environment option of the command. I tried DAYS="'45 days'". Does not work.
– Aniket Thakur
Nov 4 '17 at 13:55




1




1




Please put that update ^^ ^^ ^^ into your question, where it belongs so that everyone can easily find it.
– roaima
Nov 4 '17 at 14:32




Please put that update ^^ ^^ ^^ into your question, where it belongs so that everyone can easily find it.
– roaima
Nov 4 '17 at 14:32












I guess it was quotes after all. Took couple of hour to figure correct combinations.
– Aniket Thakur
Nov 4 '17 at 14:39




I guess it was quotes after all. Took couple of hour to figure correct combinations.
– Aniket Thakur
Nov 4 '17 at 14:39










1 Answer
1






active

oldest

votes

















up vote
0
down vote













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 -



  1. Quotes in env_variables

  2. Use of eval

  3. Single quote in command string i.e $env_variables

Reference - https://gist.github.com/andywirv/f312d561c9702522f6d4ede1fe2750bd






share|improve this answer



























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    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 -



    1. Quotes in env_variables

    2. Use of eval

    3. Single quote in command string i.e $env_variables

    Reference - https://gist.github.com/andywirv/f312d561c9702522f6d4ede1fe2750bd






    share|improve this answer
























      up vote
      0
      down vote













      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 -



      1. Quotes in env_variables

      2. Use of eval

      3. Single quote in command string i.e $env_variables

      Reference - https://gist.github.com/andywirv/f312d561c9702522f6d4ede1fe2750bd






      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        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 -



        1. Quotes in env_variables

        2. Use of eval

        3. Single quote in command string i.e $env_variables

        Reference - https://gist.github.com/andywirv/f312d561c9702522f6d4ede1fe2750bd






        share|improve this answer












        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 -



        1. Quotes in env_variables

        2. Use of eval

        3. Single quote in command string i.e $env_variables

        Reference - https://gist.github.com/andywirv/f312d561c9702522f6d4ede1fe2750bd







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 4 '17 at 14:38









        Aniket Thakur

        243111




        243111












            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?