Search code examples
bashreadlinegnome-terminal

Unable to print user input after executing the script by opening the gnome-terminal


I am trying to make the script which executes on terminal on double click and should ask for user input. To execute script open the gnome-terminal which will execute further script. After taking user input in RESP it unable to print the value passed(y/n). Gnome-terminal with nautilus.

gnome-terminal -- bash -c "read -p 'Include log?(y/n)' RESP
echo '$RESP'
    if[ '$RESP' = 'y' ]; then
       //logic for yes
    else
       //logic for no
    fi; 
exec bash"

echo $RESP not printing anything?


Solution

  • Try this

    bash -c "read -p 'Include log?(y/n)' RESP
    echo \$RESP
    if [ \$RESP = 'y' ]; then
      echo y
    else
      echo n
    fi"
    

    You need to escape the $ for your variables instead of putting it into '