LinuxQuestions.org
Help answer threads with 0 replies.
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 10-18-2008, 01:18 PM   #1
longlostname
LQ Newbie
 
Registered: Oct 2008
Posts: 4

Rep: Reputation: 0
Invoking script files from File Manager - HowTo ?


I am a Knoppix newbie. I am using Knoppix v5.1.1.

I am wanting to create the equivalent of DOS batch files (shell scripts) and execute them from the Windows Explorer (Linux File Manager - Konqueror) GUI window by double-clicking on them.

I have written a shell script, named 'myhello.sh'.
*********************
#!/bin/sh

echo "Hello"

exit 0
*********************

I have selected
K Menu/System/More Applications/File Manager - Super User Mode.
This opens a 'root - Konqueror' window.

I have stored the script file on the C drive, which in this case is '/media/hde2/', in the '/Work' subdirectory.

I have right-moused on the 'myhello.sh' file, checked the 'Permissions' tab and 'is executable' is checked.

I single-click on it and nothing seems to happen.
I double-click on it and nothing seems to happen.
I right-mouse and choose 'Open in New Window' and I get a message asking 'Do you really want to execute file:////media/hde2/Work/myhello.sh?'. I click on 'Execute', a new Konqueror window opens, and nothing seems to happen.

I would expect a command line window to open, and the word "hello" to display.

Since all of the Knoppix environment is wiped at each reboot, I am needing to put my files into a subdirectory on the 'C' drive so that I can use them at the next Knoppix boot.

This seems very fundamental, but I cannot seem to find any documentation to help me get started.

I have tried it multiple ways, using '#!/bin/bash', different file name extensions, etc, but still no results.

Can someone please assist me with this?

Thanks.
 
Old 10-18-2008, 02:34 PM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959
The main problem is that you "expect" a command line window to open. But shell scripts don't do that by default. You have to specifically design the script to open up a shell or dialog window, otherwise it will only run as a background process. I'm sure your script is running, but there's no way for it to display the output, so you don't see anything.

At the very least you can create a kde shortcut to the script and use the "advanced option" to to run the script in a terminal. That will give you a console window to view the output in.
 
Old 10-19-2008, 11:04 AM   #3
longlostname
LQ Newbie
 
Registered: Oct 2008
Posts: 4

Original Poster
Rep: Reputation: 0
David the H.,

Thank you VERY much for the response.

Can you please elaborate with details on what you are describing or please point me to an example?

I would like to see the execution of the scripts, line by line, similar to the way you do in DOS, for debugging purposes.

You said that my script was running as a background process with no way to display the output. I have another script that I was trying to learn with called 'mykwrite.sh':

//////////////////
#!/bin/sh

kwrite

//////////////////

It was my expectation that this would open the kwrite editor, but once again, nothing happened. I took out the 'exit 0' thinking that perhaps it was starting and stopping before I saw it.

Can you help me get this straight with some good examples?

Thanks.
 
Old 10-19-2008, 12:04 PM   #4
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,072

Rep: Reputation: 384Reputation: 384Reputation: 384Reputation: 384
Quote:
Originally Posted by David the H. View Post
The main problem is that you "expect" a command line window to open. But shell scripts don't do that by default. You have to specifically design the script to open up a shell or dialog window, otherwise it will only run as a background process. I'm sure your script is running, but there's no way for it to display the output, so you don't see anything.
That's just one of the problems. The other is that, even if it ran, the window will close at the speed of light after the script is run.

Quote:
At the very least you can create a kde shortcut to the script and use the "advanced option" to to run the script in a terminal. That will give you a console window to view the output in.
This is an option. Probably the best. Maybe there's an option somewhere to leave the window open after the script is run. You could use the -e parameter with most terminal emulators to run a given script. However, you would need to add a "read" statement at the end of your script, so the script pauses until you press enter.

Code:
xterm -e /path/to/myscript.sh
About your other script, it should work. What does happen if you run it manually into a terminal?
 
Old 10-19-2008, 12:20 PM   #5
longlostname
LQ Newbie
 
Registered: Oct 2008
Posts: 4

Original Poster
Rep: Reputation: 0
i92guboj,

Thank you for the response.

After posting my last question, I went into the /usr/bin/ subdirectory to look at existing shell scripts. Of course, there are many of them to choose from. I looked at the syntax and the file naming.

What my overall, real question is, how do I invoke a shell script? How do I invoke a shell script WITHOUT manually typing it at the root command line? I am creating the scripts to cut down on the repeated, excessive amount of typing that I am already having to do.

All I want to do is create some scripts that have sequences of commands that I have to frequently do, and then be able to double-click on the script to invoke them. Just as I frequently do in a MS Windows environment. I create some .BAT files that have DOS commands in them, browse for them using File Manager, and them double-click on them to invoke them.

I have tried to invoke the original system shell scripts in the /usr/bin/ directory using the Konqueror GUI and nothing happens. I can open a root terminal, manually type the /usr/bin/scriptname, and it runs. Is it actually necessary to create a script that invokes the second script for this to be done? That seems like overkill for a simple function.

All I want to do is to be able to browse for the script in a GUI File Manger, double-click on it, and have it invoke. I am a newbie so I assume that I am missing something here.

Can someone please help me with this?

Thanks.
 
Old 10-19-2008, 12:41 PM   #6
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,072

Rep: Reputation: 384Reputation: 384Reputation: 384Reputation: 384
Quote:
Originally Posted by longlostname View Post
What my overall, real question is, how do I invoke a shell script? How do I invoke a shell script WITHOUT manually typing it at the root command line? I am creating the scripts to cut down on the repeated, excessive amount of typing that I am already having to do.
You need to understand that the problem is not running the script. It will run even if you can't see it. The problem is that if you need to see what's happening, then you need to launch a terminal emulator. Linux programs usually will not do anything that you didn't ask for. That includes opening terminal emulators.

Quote:
All I want to do is create some scripts that have sequences of commands that I have to frequently do, and then be able to double-click on the script to invoke them. Just as I frequently do in a MS Windows environment. I create some .BAT files that have DOS commands in them, browse for them using File Manager, and them double-click on them to invoke them.
It should just work if you use the scripts to launch graphical programs, or to do something that doesn't need user interaction. For anything else, you will have to find the means to open a terminal and run the script on it. You don't need one script to call another. Just use the command that I instructed you above on the link, instead of putting the script name alone. Or, use the kde builtin functionality to launch the script on a terminal window, it's a checkbox somewhere in the link properties (I can't be more specific, I don't have kde installed).

Quote:
I have tried to invoke the original system shell scripts in the /usr/bin/ directory using the Konqueror GUI and nothing happens. I can open a root terminal, manually type the /usr/bin/scriptname, and it runs.
Well, as said, it will run on the background. Running most of the binaries in /usr/bin via a click is senseless anyway, since they are designed to be used on command line.
 
Old 10-19-2008, 01:19 PM   #7
longlostname
LQ Newbie
 
Registered: Oct 2008
Posts: 4

Original Poster
Rep: Reputation: 0
i92guboj,

Thank you very much for your help and patience.

Please understand that I am a newbie and that I am not trying to be difficult.

Based on what I am understanding, Linux lacks a very simplistic interface that has been available since the very first version of MS Windows and that is to be able to invoke a script file from a GUI interface. Since DOS v3, I have been able to go to the command line and manually type and type and type directory paths and filenames and commands. With the introduction of MS Windows, much of that workload was eliminated by the fundamental use of a File Manager GUI. No longer was it necessary to go to a command prompt and type the directory path and filename in order to start a script file that would open a command interface and invoke the script file that would have screen input/output. My very simple "myhello.sh" cannot be invoked from a Linux GUI and display "hello" on the screen. The existing Linux system scripts in /usr/bin/ that provide input/output cannot be invoked from a GUI. It is necessary to open a terminal interface, type the directory patch to the script, and then type the script filename. This is the same functionality that I had in DOS v3.

I am very disappointed and frustrated that I have put so much time into this only to find that Linux lacks this fundamental feature.

Thanks for your help.
 
Old 10-19-2008, 01:25 PM   #8
Total-MAdMaN
Member
 
Registered: May 2008
Distribution: Gentoo
Posts: 306

Rep: Reputation: 34
You can invoke scripts from the GUI. They just run in the background unless they're told to display the terminal. This has already been mentioned in this thread.
 
Old 10-19-2008, 01:36 PM   #9
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,072

Rep: Reputation: 384Reputation: 384Reputation: 384Reputation: 384
Quote:
Originally Posted by longlostname View Post
Based on what I am understanding, Linux lacks a very simplistic interface that has been available since the very first version of MS Windows and that is to be able to invoke a script file from a GUI interface.
No. As I said, you need to implicitly configure it to do so. Linux will not do it if you don't ask for it. It's not that hard to understand.

Quote:
Since DOS v3, I have been able to go to the command line and manually type and type and type directory paths and filenames and commands. With the introduction of MS Windows, much of that workload was eliminated by the fundamental use of a File Manager GUI. No longer was it necessary to go to a command prompt and type the directory path and filename in order to start a script file that would open a command interface and invoke the script file that would have screen input/output. My very simple "myhello.sh" cannot be invoked from a Linux GUI and display "hello" on the screen. The existing Linux system scripts in /usr/bin/ that provide input/output cannot be invoked from a GUI. It is necessary to open a terminal interface, type the directory patch to the script, and then type the script filename. This is the same functionality that I had in DOS v3.
If you don't want to see it I won't repeat it again. The functionality is there, just learn how to use it. Lots of people do so.

It has been explained -by me and others- in this thread at least two different ways to do what you want. There are many others which I simply won't bother to explain if you don't want to read them. Also: if you really like the way windows works there's no point in using linux. But if you do: please, assume that you will have to learn. There's absolutely no reason why linux should work the same way that windows does. It would be like asking windows to work the same way that linux does (absurd, isn't it?).

Besides that, we are talking about the X server and your graphical environment, which is nothing really related to linux. You would get the same behaviour under any other OS using an X server.

I don't want to sound harsh, but if you ask for help you should try to read the advice that people give to you. And if it doesn't work, try describing what you did, and how it failed. Otherwise we have no way to help you.
 
  


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
Invoking a PHP script - sometimes the full path is required sneakyimp Linux - Newbie 4 05-26-2008 05:38 PM
Invoking a shell script remotely. niks27 Linux - Newbie 1 10-11-2007 07:22 AM
bash script--variables have unexpected values on invoking mplayer stairwayoflight Programming 5 07-08-2007 11:17 AM
howto write a script to echo files with spaces in the name dsids Linux - Newbie 1 11-28-2006 07:18 AM
How to start a Tcl/Tk script by simply invoking the script file itself ? cyu021 Programming 2 10-10-2004 11:00 AM


All times are GMT -5. The time now is 01:16 AM.

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