LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 07-15-2008, 12:39 PM   #1
david0287
LQ Newbie
 
Registered: May 2008
Posts: 6

Rep: Reputation: Disabled
Question Running shell scripts in KDE


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.

Thanks for your time.
 
Old 07-15-2008, 01:31 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by david0287 View Post
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.
 
Old 07-15-2008, 01:32 PM   #3
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,987

Rep: Reputation: 388Reputation: 388Reputation: 388Reputation: 388
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.
 
Old 07-15-2008, 02:51 PM   #4
david0287
LQ Newbie
 
Registered: May 2008
Posts: 6

Original Poster
Rep: Reputation: Disabled
Run as

Shell scripts can be executed. I want to know which application to set with "run as.." to execute the script.
 
Old 07-15-2008, 03:57 PM   #5
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,987

Rep: Reputation: 388Reputation: 388Reputation: 388Reputation: 388
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.
 
Old 07-15-2008, 03:59 PM   #6
springshades
Member
 
Registered: Nov 2004
Location: Near Lansing, MI , USA
Distribution: Mainly just Mandriva these days.
Posts: 317

Rep: Reputation: 30
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
 
Old 07-15-2008, 04:57 PM   #7
tommytomthms5
Member
 
Registered: Sep 2007
Distribution: debian based
Posts: 308

Rep: Reputation: Disabled
i believe the short answer is /bin/bash
 
Old 07-15-2008, 08:06 PM   #8
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Quote:
Originally Posted by springshades View Post
<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."
 
Old 07-15-2008, 08:32 PM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
How to write shell scripts:

http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/

nice Linux guide:
http://rute.2038bug.com/index.html.gz

short article re conceptual differences MS v Linux:
http://linux.oneandoneis2.org/LNW.htm

Welcome to LQ
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Running shell scripts on Apache server anirbande Linux - General 2 12-01-2006 08:44 AM
Running shell scripts on Apache server anirbande Linux - General 2 12-01-2006 08:43 AM
Running shell scripts from Java cmpich Programming 1 04-19-2005 04:36 AM
running shell scripts using Java niravk8 Programming 2 02-09-2005 09:42 AM
running shell scripts salparadise Linux - Newbie 2 12-21-2002 05:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration