0

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.

Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227
Nir
  • 1,265
  • 7
  • 23
  • 34

1 Answers1

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.

Simon Sudler
  • 126
  • 3
  • 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 08:11