LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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, 01: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, 02:31 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,960

Rep: Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693
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, 02:32 PM   #3
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,477

Rep: Reputation: 191Reputation: 191
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 02:36 PM.
 
Old 07-15-2008, 03: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, 04:57 PM   #5
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,477

Rep: Reputation: 191Reputation: 191
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, 04:59 PM   #6
springshades
Member
 
Registered: Nov 2004
Location: Near Lansing, MI , USA
Distribution: Mainly just Mandriva these days.
Posts: 315

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 05:07 PM. Reason: extra note
 
Old 07-15-2008, 05:57 PM   #7
tommytomthms5
Member
 
Registered: Sep 2007
Distribution: debian based
Posts: 305

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

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
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, 09:32 PM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 09:44 AM
Running shell scripts on Apache server anirbande Linux - General 2 12-01-2006 09:43 AM
Running shell scripts from Java cmpich Programming 1 04-19-2005 05:36 AM
running shell scripts using Java niravk8 Programming 2 02-09-2005 10:42 AM
running shell scripts salparadise Linux - Newbie 2 12-21-2002 06:40 AM


All times are GMT -5. The time now is 01:09 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration