PDA

View Full Version : Shell Script.


bsdnewbie999
07-10-2008, 02:52 PM
How do I create a shell script that run the following command.?


mplayer -playlist r1live.ram

ocicat
07-10-2008, 03:04 PM
How do I create a shell script that run the following command.?


mplayer -playlist r1live.ram


Place the following into a file:

#!/bin/sh

mplayer -playlist r1live.ram
Assume the filename is playlist. Also note that "#!/bin/sh" must begin on line 1, column 1.
Add executable rights to the file:

chmod +x playlist

Carpetsmoker
07-10-2008, 11:17 PM
Maybe using an alias is simpler/faster, for example:

alias mp 'mplayer -playlist r1live.ram'

TerryP
07-11-2008, 01:29 AM
If the script is not being executed from the same directory as the r1live.ram file, you might want to put an explicit path.

mplayer -playlist ~/Music/Playlists/r1live.ram


or where ever you put the playlist.



This is especially useful if you intend to use this script as part of some kind of menu/dock or desktop shortcut.

18Googol2
07-11-2008, 03:43 AM
Maybe using an alias is simpler/faster, for example:

alias mp 'mplayer -playlist r1live.ram'

I dont think it would be faster because everytime you start a new shell session, the shell have to read through the startup script file (perhaps alias file as well) again


Place the following into a file:

#!/bin/sh

mplayer -playlist r1live.ram
Assume the filename is playlist. Also note that "#!/bin/sh" must begin on line 1, column 1.
Add executable rights to the file:

chmod +x playlist


You can just put

mplayer -playlist r1live.ram

into the file playlist and do

bash/sh playlist

Im sure you recognize it raises a fairly serious security issue here :)

Carpetsmoker
07-11-2008, 03:53 AM
Maybe using an alias is simpler/faster, for example:

alias mp 'mplayer -playlist r1live.ram'

I dont think it would be faster because everytime you start a new shell session, the shell have to read through the startup script file (perhaps alias file as well) again

Hm? It would do this anyway ...?

Using an alias won't spawn an instance of sh, using a script does ...

But what I mainly meant was that it's faster/easier to set up and maintain, especially if you have lots of little shortcuts like this ... This is how I prefer to do things.

TerryP
07-11-2008, 06:38 AM
From FreeBSDs manual on /bin/sh


Unlike older versions of sh the ENV script is only sourced on invocation
of interactive shells. This closes a well-known, and sometimes easily
exploitable security hole related to poorly thought out ENV scripts.



How ksh and bash handle it when called as /bin/sh, I wouldn't know off hand.

bsdnewbie999
07-12-2008, 06:52 AM
Maybe using an alias is simpler/faster, for example:

alias mp 'mplayer -playlist r1live.ram'

What is alias? I need to paste the code into a file ? And chmod +x ?

18Googol2
07-12-2008, 07:10 AM
Nope, the % indicates its a command.

Actually, the correct command is

% alias mp='mplayer -playlist r1live.ram'

The above alias is valid in the current shell session only. You might wanna put it in the shell startup script so that the alias will be set in every new shell session

bsdnewbie999
07-12-2008, 01:54 PM
I see.

I have another question. Can I write a GUI shell program (like a calculator program) ?

Carpetsmoker
07-13-2008, 04:16 AM
Actually, the correct command is

% alias mp='mplayer -playlist r1live.ram'

Ommiting the = works fine in (t)csh, but according to IEEE Std 1003.1 (http://www.opengroup.org/onlinepubs/009695399/utilities/alias.html) the = is required ... So better get in to the habit of using it ... Thank you.

I have another question. Can I write a GUI shell program (like a calculator program) ?

There are some tools, like dialog, xdialog, zenity, ad probably a few more ...

bsdnewbie999
07-13-2008, 04:25 AM
Besides shell script, is there other programming language that run GUI in OpenBSD like C, java...etc ?

Carpetsmoker
07-13-2008, 04:35 AM
Yes, just about any programming language can (Including C and Java).

ocicat
07-13-2008, 05:52 AM
Besides shell script, is there other programming language that run GUI in OpenBSD like C, java...etc ?

Java Swing
Python/wxPython
Perl/TK

TerryP
07-13-2008, 08:18 AM
I believe the Korn Shell has some form of access to a GUI toolkit but have never actually looked into it.


Beyond scriptable interfaces like dialog/kdialog and whatever else is out there (which can create portability nightmares for scripts) a general purpose programming language and GUI toolkit is usually best for doing non-trival work.


If your not familiar with GUI toolkits, I'd suggest Qt -- it is well documented (in C++) and has bindings to many languages. PyQt (Python bindings to Qt) also makes things very painles to use/learn if you know enough C++ to follow the Qt documentation.


If your familiar with either language, Javas Swing and just about all of Pythons bindings to toolkits are probably good choices as well.


You could probably do a GUI application on OpenBSD in Assembly if you wanted to get jigy with it.

BSDfan666
07-13-2008, 11:20 AM
Why hasn't anyone mentioned the curses library? :)

18Googol2
07-13-2008, 11:26 AM
Why hasn't anyone mentioned the curses library? :)

Its not GUI, it is still text based

BSDfan666
07-13-2008, 11:45 AM
Its not GUI, it is still text based
It's a GUI according to my books, "Graphical User Interface", while it might just be a clever use of escape codes... looks pretty graphical too me.

Carpetsmoker
07-13-2008, 05:52 PM
Text user interface

BSDfan666
07-13-2008, 08:02 PM
Fuck tradition, I can think for my self, it's a GUI. :)

TerryP
07-13-2008, 08:38 PM
Hahahahahhahaha


I've never considered curses fun to program (in C) but what ever rocks your boat.

bsdnewbie999
07-15-2008, 08:54 AM
I think I'll use Java. Since I don think Zenity can fufill my requirements.