Running a bash script

Is it possible to run a bash script directly without the options box displaying?

I want to Run my script not have to choose to Run it from an options box.

ScriptOptions

You can run it from the command line.
The first line needs to be
#! /bin/bash
assuming you are using a bash shell script

And you need to make the file executable… eg , if it is called
script. bash do
chmod 755 script.bash
to give execute permission to all users.

Then just do
./script.bash
That will run it

If you have a lot of scripts, it is best to put them in some place that is in your search path … eg -/bin or /usr/local/bin

Regards
Neville

2 Likes

I get the same option box in Zorin. But in Mint, I go to the command line and type ./name of script to run the bash script that is in my home directory.

Thank you, for both replies. This applies to executing the script from the Terminal, but I really want to Run a script directly by double clicking on its file icon in the file manager. The script is executable so this works, but always displays the options box and that is what I want to bypass. Maybe there is another command I need to insert into my script to achieve this?

I think it is possible to setup the file manager so a double click executes a file. It is controlled by the file type. The file manager has to be able to recognise the file type and know that it is to be executed rather than displayed. Using a standard extension in script names may help with this.

Have a look at your scripts file type with the file statement. Then see if your file manager agrees. Then try to use the menus in the file manager to tell it thst this file type is to be executed.

Be aware that making files executable by clicking in the file manager can be a hazard. You might accidentally click something and have it run and do some damage.

Does not answer the question. @nevj, again, backward thinking. :smiley:

I think, there should be an option where you can choose the default action for a .sh file. You should most likely find such option in the GUI file manager’s option menu.

1 Like

Never occured to me that anyone would want to execute something from the file manager.

nevj - run from a file manager? yes us GUI’ers do! :pleading_face:

Thanks for your suggestion. Easy solution, Nemo > Edit > Preferences > Behaviour > Run Executable Text Files when they are opened.

And thanks for warning, if I need to display a script file I will right click on it and open with text editor

3 Likes

Never occurred to me, that a normal person would want to open the terminal to do anything.

1 Like

Akito - open/use the terminal? yes that’s rather my approach too! Though the terminal does have important uses I am learning… :thinking:

2 Likes

I use the terminal all the time, but it is because I want to, plus I know what I’m doing. Though, I think it’s wrong when Linux forces the user to do it, because the GUI capabilities are so extremely limited and in some parts inherently broken.

1 Like

I agree to some extent, Linux desktops are mostly an enthusiast thing, not for the mainstream, and frankly after seeing the DISASTER that the Gnome developers have inflicted on Gnome users, the usability nightmare, the lack of care from the developers, where I’d previously (erroneously) thought Linux on the Desktop was making progress and inroads, but if the “default” beginner distro (Ubuntu 22.04) can get so much wrong, what hope is there? It’s like nearly everything up to Ubuntu 20.04 was “progress” (I actually liked Unity) - Ubuntu 22.04 and Gnome 42, is like 1 step forward, a sports stadium sized step backwards.

I will continue to use it, because I’m an enthusiast and I can live with the limitations, and I’m quite happy to break out the terminal where needed. And I REALLY DON’T CARE, I’m happy to keep using the terminal if needed. If there was NO TERMINAL, I wouldn’t use Linux or MacOS… I’d still be running Solaris, or FreeBSD if that was the only way to get a terminal.

Note : this argument about the terminal, isn’t that a bit like MS DOS batch files running by double clicking on them from the Windows explorer? Isn’t that like a MAJOR vulnerability? e.g. I just wrote a very rudimentary batch script… Unless I put a pause at the end, it just runs (double click) and I get no feedback… Imagine if it was doing something destructive?

My opinion? If people want to run shell scripts, maybe they should know the terminal? Isn’t what you’re staying like asking a powershell script writer not to use the powershell CMD style window… Most PowerShell users, and script writers I know, actually fire up a PowerShell window and run their powershell interactively by using the Windows Power shell CLI - that’s basically Microsoft’s version of “break out the terminal”…

In another note - I just tried to get Windows Terminal installed in one of the 6 Windows 10 VDI’s I use for my job, and one of the settings was to allow administrator option (for powershell), and guess what? Now Windows Terminal can’t start 'cause :

What I’m trying to do is I guess “outside” the box, and not what everyday users would be doing - I really couldn’t be arsed contacting my system administator - I don’t even know who that is! But if I did, no doubt I’d get a tisk tisk and a rap over the knuckles for trying to do “god” stuff in their “domain” :smiley:

Maybe I can run the registry editor and see if that things in one of the registry hives I’m allowed to edit / update… Registry? I can’t believe we’re still doing this sorta shit in Windows! Gimme a terminal and a bash script over the Windows Registry any day :smiley: - the registry, AKA the stuff that nightmares are made of :heart: - like Clive Barker’s hellcube in the Hellraiser universe :smiley: :heart:

3 Likes

@daniel.m.tripp ,
I cant see anything to disagree with there

@steveredshaw and all :wave:

Hi,

just wanted to let you know how I do it:

example:

I once wrote a script called “2skript_für_e-books_und_man-pages.sh” and it´s located here:

media/rosika/f14a27c2-0b49-4607-94ea-2e56bbf76fe1/LINK-FARM/Scripte/Scripte_für_focal/2skript_für_e-books_und_man-pages.sh

Now I created a .desktop fille referring to that script:

bat e-books_and_man-pages.desktop 
───────┬───────────────────────────────────────────────────────────────────────────────────────
       │ File: e-books_and_man-pages.desktop
───────┼───────────────────────────────────────────────────────────────────────────────────────
   1   │ [Desktop Entry]
   2   │ Version=1.0
   3   │ Name=e-books_and_man-pages       
   4   │ Comment=e-books_and_man-pages
   5   │ Exec=/media/rosika/f14a27c2-0b49-4607-94ea-2e56bbf76fe1/LINK-FARM/Scripte/Scripte_für_
       │ focal/2skript_für_e-books_und_man-pages.sh
   6   │ Icon=utilities-terminal
   7   │ Terminal=true
   8   │ Type=Application
   9   │ Categories=Application;
  10   │ Name[de_DE]=e-books_and_man-pages       
  11   │ Comment[de_DE]=e-books_and_man-pages

I placed this .desktop file on my desktop. So all I need to do is double-click on it and the script runs.

However: from the LXQt desktop environment (I´m using Lubuntu) a popup window still opens asking me what I want to do. I undesrtand this is what you want to circumvent.

BUT:

Double-clicking on the .desktop file from within thunar (my file manager) lets the script run directly and immediately, without any popup window in the middle of it.
I guess this is what you wanted to achieve. :blush:

Many greetings from Rosika :slightly_smiling_face:

4 Likes