I came across this line
if [ ! -t 0 ]; then x-terminal-emulator -e "$0"; exit 0; fiwhich I can write at the top of a script and when clicking on the script file in nautilus, the script will open itself in a terminal window so that I can see the output.
Now there is the problem that this command
read -n1 -r -p "Press any key to continue..." keyin this case will not wait for a key press.
My guess is that x-terminal-emulator may be the reason, but I haven't found any other solution to double click a script file in Nautilus and get a new terminal window where the script will run.
72 Answers
Cannot reproduce. This code
#!/bin/bash
if [ ! -t 0 ]; then x-terminal-emulator -e "$0"; exit 0; fi
echo "new window"
read -n1 -r -p "Press any key to continue..." key
echo byewhen run with ./foo.sh </dev/null opens in a new terminal and waits for a key press.
You'll need to be more explicit about your code.
1read -r -p "Press any key to continue..." keywaits for the Return key, no matter if #!/bin/bash has been used or not.
When
#!/bin/bashis at the top of the script, -n1 will work and will wait for any key.