Embedding Commands

Forum: Programming and Scripting
Topic: Embedding Commands
started by: Aussie

Posted by Aussie on Sep. 22 2005,15:13
I am wondering if there is a way to execute commands from a file - as you do in DOS with a batch file?

For instance, the command "mydsl-load opt/snake.dsl" will do the same as going into emelfm, going to the dsl package and clicking Mydsl.

It would be nice to be able to embed this command into a submenu in the "Right click context menu" file for example.


Posted by larkl on Sep. 22 2005,15:29
Have you tried something like a bash script?  This should be easy.  I'm sure that you could then make it run from an icon.  As far as embedding into a right-click menu, I don't have a clue.
Posted by mikshaw on Sep. 22 2005,15:38
Yes....this is in my opinion the most fundamental feature of a GNU system.  The Bash shell is your base in DSL.  When you log in, you have a shell that opens other shells that open other shells, etc....and they can, for the most part, all be manipulated through bash.  Bash can be used interactively, as from a terminal prompt, and can also be used through a script (the equivalent of a batch file). The mydsl-load executable, and all other DSL-specific executables, are scripts...many of them Bash scripts. Check out the bash documentation at tldp.org for more info.

As far as "embedding" a command in the right-click menu, it should be very easy, depending on what application you are referring to.  In Fluxbox, the file is /home/dsl/.fluxbox/menu.  The syntax is [exec] (LABEL) {COMMAND}.  In Emelfm i think you have a gui interface for manipulating menus and commands.

Posted by Aussie on Sep. 22 2005,15:40
Hi Larkl,

Putting it into the menu I can do, it's the actual embedding of a command into a file (so it executes) that I don't know how to do.

I don't know what a bash script is yet.


Posted by Aussie on Sep. 22 2005,15:49
Quote (mikshaw @ Sep. 22 2005,23:38)
As far as "embedding" a command in the right-click menu, it should be very easy, depending on what application you are referring to.  In Fluxbox, the file is /home/dsl/.fluxbox/menu.  The syntax is [exec] (LABEL) {COMMAND}.

Hi Mikshaw,

I tried putting the command straight into the menu file using the format you suggested, but it didn't execute. That's why I'm asking about "embedding" commands.

I tried other commands such as "touch" and they won't execute either.

I will have to read up on bash scripts tomorrow, sounds interesting  :)


Posted by larkl on Sep. 22 2005,15:54
It's pretty easy.  In your text editor, start the file with:


then add whatever you want on the next lines:

mkdir <...> or whatever

save it and make it executable with chmod and you should be good to go.  Have fun!

Posted by Patrick on Sep. 22 2005,17:54
An other example:

killall -9 wmclockmon
/cdrom/keep/dockable/usr/bin/wmclockmon -tm 1 &
#this batchfile restart wmclockmon

this file (when executed) kills a process (an other executed file) with the name: wmclockmon (a clock ). After that it start the clock

-When there's a # in front of a line, everything in that line is NOT executed
-When there's a & at the end of a line, the command's in that line are executed AND the process moves on to the next line (doesn't wait for the commands in that line to end)
-When there's not a & at the end of the line, the process waits until every command is ready with it's task.
-the first line of a "batch-file" is: #!/bin/sh

Just an example, i hope i got it all right (i am learning just like you)

Posted by cbagger01 on Sep. 23 2005,05:00
BASH scripts are a million times more powerful than old DOS BAT files.

If you want to learn more about BASH, here is the place:

< http://www.tldp.org/LDP/abs/html/ >

Posted by Aussie on Sep. 23 2005,05:17

Ok, I created an executable bash file:

mydsl-load /opt/circuslinux.dsl

I saved it as /opt/circus

Typing /opt/circus in a terminal window will add the circus game to mydsl in the context menu, and clicking on it will open and run the game.

However, adding [exec] (Circus) {/opt/circus} to  a submenu in the context menu file still does nothing when I click on that menu item.

Do I have to "call" the bash file somehow in my menu file for it to work?

There is a reason why I'm doing all this, so any help will be appreciated  :)


Posted by Aussie on Sep. 23 2005,06:24
Quote (Aussie @ Sep. 23 2005,13:17)
mydsl-load /opt/circuslinux.dsl


The mydsl-load command loads the game into /usr/games/

I then have to "call" the game by adding an extra line:


I also have to leave the "&" option out of the first command, to give the system time to load the game before "calling" it.

So my bash file is:

mydsl-load /opt/circuslinux.dsl

Now the link in the context menu works, and the game starts automatically (without adding a mydsl entry in the context menu).

The reason I wanted to do this is to only load applications when I need them, rather than have mydsl load everything at start-up. This saves time and resources.

If I can do the same with other apps such as Office, I assume I'm going to have a very fast and versatile OS that is bulletproof - since it's a frugal install.

We shall see  :)


Posted by larkl on Sep. 28 2005,22:53
Have you tried doing this with the OPTIONAL in frugal?  I'm finding it to work well.  You download the apps into /mnt/hda1/optional using mydsl, then you use the right click menu to install them only if you need them.  You have to add the path to the opt in grub, but that's about it.  Your approach works (obviously!), but it's more to re-create if you have to reinstall or something.
Posted by vrden on Nov. 18 2005,17:11
This is a nice thread, good information is provided. I have one comment to make concerning stream programming (a Unix concept from decades ago) and that "&" shell directive. The meaning of "&" is [background this process]. Which is implemented as a "fork" system call. Unix is a stream environment because everything is launched inside a process, the "fork" call instructs the batch command to launch a new process for the command. This is why the calling process continues without delay.

So, to think of the application waiting for the first call to complete before continuing is technically wrong, and leads to problems in design as your batch programming progresses. Specifically, when you fork a new process (to load the game), the new process looses all contact with the parent process (your script) and the next call (to execute the game) fails because as far as it is concerned, the game is not loaded yet. Yes, it is loaded but within the separate (forked) process, and therefore not available to the parent process.

Technical I know, but some day you'll appreciate the nuance.

Powered by Ikonboard 3.1.2a
Ikonboard © 2001 Jarvis Entertainment Group, Inc.