Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi I have migrated from Windows and I am looking for an alternative for batch files.
I have been told that i can create a shell script in any text file with any filename extension and execute it with a terminal.
What I need is to run it directly by clicking on it. Is there a recognized file name extension that has an ("open with") set for an executing application so that I can just click on the file and some program will execute it for me?
I need this so that when the file is downloaded with Firefox I can execute the script by selecting open with.. (program), instead of saving it to the disk, finding it, opening the terminal and executing it.
Hi I have migrated from Windows and I am looking for an alternative for batch files.
I have been told that i can create a shell script in any text file with any filename extension and execute it with a terminal.
What I need is to run it directly by clicking on it. Is there a recognized file name extension that has an ("open with") set for an executing application so that I can just click on the file and some program will execute it for me?
I need this so that when the file is downloaded with Firefox I can execute the script by selecting open with.. (program), instead of saving it to the disk, finding it, opening the terminal and executing it.
You are correct that you can create a shell script with any extension, and execute it. There's a bit more to it than that, though, as I'm sure you're aware (permissions on the file, what shell you write it in, etc.), but that's generally it. Whatever commands you can enter from a terminal window, you can run from a shell script.
By default, 99% of shell scripts are named "<filename>.sh". This MAY be associated with a 'run as" from Firefox, but you can associate ANY name with almost any action. Linux won't tell you what to do, but it will give you the flexibility to do what you want.
If you're new to this world, I'd strongly suggest a book on shell scripting. There are tons out there, as well as lots of guides on the internet. Good luck.
Exactly which command do you want to run to open these downloaded files? There is probably a gui front end for that terminal command if you are talking about any popular file format and if that's the case, you can set the "open with" preference in KDE Control Center>KDE Components>File Associations. Or you can direct firefox to use that gui application to open that file type through the "open with" dialog.
Last edited by kilgoretrout; 07-15-2008 at 01:36 PM.
The script itself is the executable so the script would be designated in the file selection dialogue in firefox. However, I doubt firefox can execute shell scripts which I assume is your problem. That's why I inquired about exactly what commands you want to run in that script. Your problem is too poorly defined to give you any meaningful help without that information.
This is pretty easy. As long as you know how to make your shell script to do what you want to do, I won't give you any advice on that part (the previous replies have already gone in that direction). The easiest way to make your script executable is to 1. set it's permissions as executable and 2. put it in your "path". I won't go into the path thing either, you can figure it out later, but I'll tell you how to get this particular task done.
1. Write your shell script file in whatever text editor you like (though a simple text editor like kate or nano is less likely to screw up something important like formatting than an office application like open office writer).
2. Save your shell script as whatever you want to name it wherever you want to save it. Just make sure you don't call it something that could possibly conflict with some other command. For example, "firefox" might not be a good idea, however, "my-firefox-script" probably isn't taken by any other program.
3. Right click on your new file, click on the "permissions" tab, and click that little box that says "is executable". Now you could potentially leave it at that and simply tell the "open with" dialog in firefox where you've put that file, but there is another step that will make this far more convenient.
4. Put it in your "path". The extent of your path can vary from system to system, however, the folder /usr/bin is almost universally in your path, so let's put it there. This can be done by opening a terminal and putting in AS ROOT (to do this, type "su" at the command prompt then put in your root password) "mv /pathtoyournewscript/nameofscript /usr/bin/" which moves the script file into the /usr/bin/ folder. Now, if you type the name of your script in a terminal, it will execute automatically.
5. Final. In the "open with..." dialog in firefox that comes up when you download something, click the drop down box, click the other option, then navigate to the /usr/bin/ folder and choose your script. I'm not 100% sure if firefox can run scripts like this to be honest. I'd have to test it.
EDIT: You CAN run it this way by clicking on it though, if that is your aim.
Last edited by springshades; 07-15-2008 at 04:07 PM.
Reason: extra note
<snip>This can be done by opening a terminal and putting in AS ROOT (to do this, type "su" at the command prompt then put in your root password) "mv /pathtoyournewscript/nameofscript /usr/bin/" which moves the script file into the /usr/bin/ folder. Now, if you type the name of your script in a terminal, it will execute automatically.</snip>
On Ubuntu and derivatives the "root" account is, by default, locked, and the "root" password not set. It is possible to unlock the root account, but that is, in almost all circumstanses, an unnecessary security risk.
Instead of su and trying to enter a non-existant password for a locked account, just use the command sudo mv /pathtoyournewscript/nameofscript /usr/bin/ which will request your password, and then execute the command as though it had been entered by "root."
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.