Bash – Double click Linux Bash Script and debug with pause commands

bashdebugging

I'm fairly good with windows .bat scripts and normally use the pause command while developing them so I can see things step by step as the script runs in the command prompt. I am trying to do something similar with a Linux Bash file. I have a very simple bash, which can be seen below…

#!/bin/bash
echo Hello World!
read -p "Press [Enter] key to continue..."

I configured Nautilus (a Linux file management program) to "Run executables when they are double clicked" but I don't see anything when I double click the script. Do I need to re-route output to the console or something?

Edit

Here is how I achieved what I wanted…

  1. Create a .sh file (I am using one from above)
  2. Open Nautilus
  3. Click Edit -> Preferences -> Behavior tab
  4. Under "Executable Text Files" choose "Ask Each Time" Radio button

Now when you click on .sh files, you will be prompted with a few options. Option "Run in Terminal" does exactly what I want. Thanks everyone for the contributions!

Best Answer

You need to launch a terminal, which in turn launches the script.

Try this:

#!/bin/sh
xterm -e "echo Hello World; read -p 'Press [Enter] key to exit ..."

This is of course impractical for a longer script. But then you can simply do:

#!/bin/sh
xterm -e /home/user/scripts/thescript.sh

and thescript.sh contains all the commands you want to use. Make sure it is executable (chmod +x thescript.sh)

Related Question