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.
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.
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.
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?
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?
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.
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.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.