execute read command from var [duplicate]











up vote
0
down vote

favorite













This question already has an answer here:




  • How can we run a command stored in a variable?

    3 answers




I want to add "debug" optio to my script, for that I added a read commands in specific places in the code. Basically it look like this:



#define it
READ_USER_INPUT_IF_IN_DEBUG_MODE="read -p 'press any key to continue:'"

#calling it
${READ_USER_INPUT_IF_IN_DEBUG_MODE}


the screen output is not as desired;



sm2edolt01.corp.nyx.com:/home/oracle/nir >./a.sh
'press


Tried to replace the ' with " as well.










share|improve this question















marked as duplicate by Kusalananda bash
Users with the  bash badge can single-handedly close bash 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 14 at 10:06


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.



















    up vote
    0
    down vote

    favorite













    This question already has an answer here:




    • How can we run a command stored in a variable?

      3 answers




    I want to add "debug" optio to my script, for that I added a read commands in specific places in the code. Basically it look like this:



    #define it
    READ_USER_INPUT_IF_IN_DEBUG_MODE="read -p 'press any key to continue:'"

    #calling it
    ${READ_USER_INPUT_IF_IN_DEBUG_MODE}


    the screen output is not as desired;



    sm2edolt01.corp.nyx.com:/home/oracle/nir >./a.sh
    'press


    Tried to replace the ' with " as well.










    share|improve this question















    marked as duplicate by Kusalananda bash
    Users with the  bash badge can single-handedly close bash 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 14 at 10:06


    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.

















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite












      This question already has an answer here:




      • How can we run a command stored in a variable?

        3 answers




      I want to add "debug" optio to my script, for that I added a read commands in specific places in the code. Basically it look like this:



      #define it
      READ_USER_INPUT_IF_IN_DEBUG_MODE="read -p 'press any key to continue:'"

      #calling it
      ${READ_USER_INPUT_IF_IN_DEBUG_MODE}


      the screen output is not as desired;



      sm2edolt01.corp.nyx.com:/home/oracle/nir >./a.sh
      'press


      Tried to replace the ' with " as well.










      share|improve this question
















      This question already has an answer here:




      • How can we run a command stored in a variable?

        3 answers




      I want to add "debug" optio to my script, for that I added a read commands in specific places in the code. Basically it look like this:



      #define it
      READ_USER_INPUT_IF_IN_DEBUG_MODE="read -p 'press any key to continue:'"

      #calling it
      ${READ_USER_INPUT_IF_IN_DEBUG_MODE}


      the screen output is not as desired;



      sm2edolt01.corp.nyx.com:/home/oracle/nir >./a.sh
      'press


      Tried to replace the ' with " as well.





      This question already has an answer here:




      • How can we run a command stored in a variable?

        3 answers








      bash shell-script






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 at 10:11









      Rui F Ribeiro

      38.2k1475123




      38.2k1475123










      asked Nov 14 at 9:56









      Nir

      42521020




      42521020




      marked as duplicate by Kusalananda bash
      Users with the  bash badge can single-handedly close bash 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 14 at 10:06


      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 Kusalananda bash
      Users with the  bash badge can single-handedly close bash 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 14 at 10:06


      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.
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          Quoting won't work, use any array:



          #define it                                                                                                          
          READ_USER_INPUT_IF_IN_DEBUG_MODE=(read -p 'press any key to continue:')

          #calling it
          "${READ_USER_INPUT_IF_IN_DEBUG_MODE[@]}"


          See this page for more details on Bash arrays handling.






          share|improve this answer








          New contributor




          Simon Sudler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.


















          • One thing though. I need that the command "${READ_USER_INPUT_IF_IN_DEBUG_MODE[@]}" will not return error in case of empty variable. Setting it to empty string resulting in command not found
            – Nir
            9 hours ago


















          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          Quoting won't work, use any array:



          #define it                                                                                                          
          READ_USER_INPUT_IF_IN_DEBUG_MODE=(read -p 'press any key to continue:')

          #calling it
          "${READ_USER_INPUT_IF_IN_DEBUG_MODE[@]}"


          See this page for more details on Bash arrays handling.






          share|improve this answer








          New contributor




          Simon Sudler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.


















          • One thing though. I need that the command "${READ_USER_INPUT_IF_IN_DEBUG_MODE[@]}" will not return error in case of empty variable. Setting it to empty string resulting in command not found
            – Nir
            9 hours ago















          up vote
          1
          down vote



          accepted










          Quoting won't work, use any array:



          #define it                                                                                                          
          READ_USER_INPUT_IF_IN_DEBUG_MODE=(read -p 'press any key to continue:')

          #calling it
          "${READ_USER_INPUT_IF_IN_DEBUG_MODE[@]}"


          See this page for more details on Bash arrays handling.






          share|improve this answer








          New contributor




          Simon Sudler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.


















          • One thing though. I need that the command "${READ_USER_INPUT_IF_IN_DEBUG_MODE[@]}" will not return error in case of empty variable. Setting it to empty string resulting in command not found
            – Nir
            9 hours ago













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          Quoting won't work, use any array:



          #define it                                                                                                          
          READ_USER_INPUT_IF_IN_DEBUG_MODE=(read -p 'press any key to continue:')

          #calling it
          "${READ_USER_INPUT_IF_IN_DEBUG_MODE[@]}"


          See this page for more details on Bash arrays handling.






          share|improve this answer








          New contributor




          Simon Sudler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          Quoting won't work, use any array:



          #define it                                                                                                          
          READ_USER_INPUT_IF_IN_DEBUG_MODE=(read -p 'press any key to continue:')

          #calling it
          "${READ_USER_INPUT_IF_IN_DEBUG_MODE[@]}"


          See this page for more details on Bash arrays handling.







          share|improve this answer








          New contributor




          Simon Sudler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          share|improve this answer



          share|improve this answer






          New contributor




          Simon Sudler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          answered Nov 14 at 10:02









          Simon Sudler

          1263




          1263




          New contributor




          Simon Sudler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





          New contributor





          Simon Sudler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






          Simon Sudler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.












          • One thing though. I need that the command "${READ_USER_INPUT_IF_IN_DEBUG_MODE[@]}" will not return error in case of empty variable. Setting it to empty string resulting in command not found
            – Nir
            9 hours ago


















          • One thing though. I need that the command "${READ_USER_INPUT_IF_IN_DEBUG_MODE[@]}" will not return error in case of empty variable. Setting it to empty string resulting in command not found
            – Nir
            9 hours ago
















          One thing though. I need that the command "${READ_USER_INPUT_IF_IN_DEBUG_MODE[@]}" will not return error in case of empty variable. Setting it to empty string resulting in command not found
          – Nir
          9 hours ago




          One thing though. I need that the command "${READ_USER_INPUT_IF_IN_DEBUG_MODE[@]}" will not return error in case of empty variable. Setting it to empty string resulting in command not found
          – Nir
          9 hours ago



          Popular posts from this blog

          Morgemoulin

          Scott Moir

          Souastre