I have created a script and put it in a folder in my path.
If I open terminal and type the name of the script it runs fine.
How do I make it so that I just double-click on the script and it opens Terminal and runs?
And leaves Terminal visible.
Basically I'm after something akin to .bat in windows
Thanks.
Help with bash script
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Topics in this forum are automatically closed 6 months after creation.
Help with bash script
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Re: Help with bash script
This isn't about getting help with a bash script; this is about configuring your specific terminal for how you want it to behave. By default, the terminal closes after you choose to "Run in Terminal" a script. You can probably configure your terminal to not close after running a script that way. Depends on the terminal you use, and as you have given us zero information about your installation we can't help with any specifics. On Cinnamon you can configure the default Terminal through its Edit > Profile Preferences menu, the Title and Command tab, there set "When command exits" to what you want.
If you have a terminal without a menu, right-click inside the terminal and select to show the menubar.
Alternatively, if you want to change it only for this one bash script, put the following at the top of your bash script:
Then start it with "Run" instead of "Run in Terminal", and it will ask for you to press the enter key before closing the terminal after the script completes. So this doesn't need above change to the terminal's settings.
If you have a terminal without a menu, right-click inside the terminal and select to show the menubar.
Alternatively, if you want to change it only for this one bash script, put the following at the top of your bash script:
Code: Select all
# if the script was not launched from a terminal, restart it from a terminal
if [[ ! -t 0 && -x /usr/bin/x-terminal-emulator ]]; then
/usr/bin/x-terminal-emulator -e "bash -c \"$0 $*; read -s -p 'Press enter to continue...'\""
exit
fi
Re: Help with bash script
Actually this is about helping to run a script, the "keep the terminal visible" comment was an aside, but useful as this is performing a download and an idea of progress is always nice.
I am running Mint 16 MATE.
My question remains. How do I make my script double-clickable?
Thanks.
I am running Mint 16 MATE.
My question remains. How do I make my script double-clickable?
Thanks.
Re: Help with bash script
Floatingshed wrote:How do I make it so that I just double-click on the script and it opens Terminal and runs?
And leaves Terminal visible.
I don't follow, can you explain a bit more what you expect to happen when you double-click the file and what doesn't? Assuming you marked the file as executable, you'll be presented with a choice to either run the script, run it in a terminal, edit it, or cancel. When you "run" a terminal isn't opened unless you added my above code. When you "run in terminal" a terminal is opened but unless you made above configuration change the terminal closes immediately after the script is done.Floatingshed wrote:My question remains. How do I make my script double-clickable?
Re: Help with bash script
Ah, when I double-click the script absolutely nothing happens, not a glimmer. No errors, nothing.
If I right click it says it is executable but opens with wine! That can't be right!
If I right click it says it is executable but opens with wine! That can't be right!
Re: Help with bash script
Ah, Wine Wonderful program. Suddenly all your text files are opened in Wine with Notepad... Stuff of nightmares and I can't fathom why anybody would want to use Notepad on Linux -- let alone having it hijack your system like this
What extension have you given your bash script? .sh? That should be safe from Wine I'd hope. Else I'm not sure how to recover from this. You'll probably have to edit the file associations in Caja. You could also look at the file .local/share/applications/mimeapps.list and remove any association to Wine for text files, that might be the simplest approach.
And check your Caja configuration; that you've set its behavior to ask you each time what to do for executable text files. Should be somewhere in Edit > Preferences I think.
What extension have you given your bash script? .sh? That should be safe from Wine I'd hope. Else I'm not sure how to recover from this. You'll probably have to edit the file associations in Caja. You could also look at the file .local/share/applications/mimeapps.list and remove any association to Wine for text files, that might be the simplest approach.
And check your Caja configuration; that you've set its behavior to ask you each time what to do for executable text files. Should be somewhere in Edit > Preferences I think.
Re: Help with bash script
Excellent! Editing the mimeapps.list has rescued my computer from the clutches of wine!
The script is now behaving as it should.
Many thanks for the help.
The script is now behaving as it should.
Many thanks for the help.
Re: Help with bash script
Phew! Glad it was fixed with that one