0

This question already has an answer here:

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.

marked as duplicate by Kusalananda bash Nov 14 '18 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

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.

  • 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 Nov 18 '18 at 16:16
  • Yes, that doens't work. Use READ_USER_INPUT_IF_IN_DEBUG_MODE=() instaed of the empty string – Simon Sudler Nov 19 '18 at 8:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.