DaemonForums  

Go Back   DaemonForums > Miscellaneous > Programming

Programming C, bash, Python, Perl, PHP, Java, you name it.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 10th July 2008
bsdnewbie999 bsdnewbie999 is offline
Package Pilot
 
Join Date: May 2008
Posts: 145
Default Shell Script.

How do I create a shell script that run the following command.?

Code:
mplayer -playlist r1live.ram
Reply With Quote
  #2   (View Single Post)  
Old 10th July 2008
ocicat ocicat is offline
Administrator
 
Join Date: Apr 2008
Posts: 3,318
Default

Quote:
Originally Posted by bsdnewbie999 View Post
How do I create a shell script that run the following command.?

Code:
mplayer -playlist r1live.ram
  • Place the following into a file:
    Code:
    #!/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
Reply With Quote
  #3   (View Single Post)  
Old 10th July 2008
Carpetsmoker's Avatar
Carpetsmoker Carpetsmoker is offline
Real Name: Martin
Tcpdump Spy
 
Join Date: Apr 2008
Location: Netherlands
Posts: 2,243
Default

Maybe using an alias is simpler/faster, for example:

% alias mp 'mplayer -playlist r1live.ram'
__________________
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things.
Reply With Quote
  #4   (View Single Post)  
Old 11th July 2008
TerryP's Avatar
TerryP TerryP is offline
Arp Constable
 
Join Date: May 2008
Location: USofA
Posts: 1,547
Default

If the script is not being executed from the same directory as the r1live.ram file, you might want to put an explicit path.

Code:
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.
__________________
My Journal

Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''.
Reply With Quote
  #5   (View Single Post)  
Old 11th July 2008
18Googol2's Avatar
18Googol2 18Googol2 is offline
Real Name: whoami
Spam Deminer
 
Join Date: Apr 2008
Location: pwd
Posts: 283
Default

Quote:
Originally Posted by Carpetsmoker View Post
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

Quote:
Originally Posted by ocicat View Post
  • Place the following into a file:
    Code:
    #!/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
Reply With Quote
  #6   (View Single Post)  
Old 11th July 2008
Carpetsmoker's Avatar
Carpetsmoker Carpetsmoker is offline
Real Name: Martin
Tcpdump Spy
 
Join Date: Apr 2008
Location: Netherlands
Posts: 2,243
Default

Quote:
Originally Posted by 18Googol2
Quote:
Originally Posted by Carpetsmoker View Post
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.
__________________
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things.
Reply With Quote
  #7   (View Single Post)  
Old 11th July 2008
TerryP's Avatar
TerryP TerryP is offline
Arp Constable
 
Join Date: May 2008
Location: USofA
Posts: 1,547
Default

From FreeBSDs manual on /bin/sh

Quote:
Originally Posted by Invocation
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.
__________________
My Journal

Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''.
Reply With Quote
  #8   (View Single Post)  
Old 12th July 2008
bsdnewbie999 bsdnewbie999 is offline
Package Pilot
 
Join Date: May 2008
Posts: 145
Default

Quote:
Originally Posted by Carpetsmoker View Post
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 ?
Reply With Quote
  #9   (View Single Post)  
Old 12th July 2008
18Googol2's Avatar
18Googol2 18Googol2 is offline
Real Name: whoami
Spam Deminer
 
Join Date: Apr 2008
Location: pwd
Posts: 283
Default

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
Reply With Quote
Old 12th July 2008
bsdnewbie999 bsdnewbie999 is offline
Package Pilot
 
Join Date: May 2008
Posts: 145
Default

I see.

I have another question. Can I write a GUI shell program (like a calculator program) ?
Reply With Quote
Old 13th July 2008
Carpetsmoker's Avatar
Carpetsmoker Carpetsmoker is offline
Real Name: Martin
Tcpdump Spy
 
Join Date: Apr 2008
Location: Netherlands
Posts: 2,243
Default

Quote:
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 the = is required ... So better get in to the habit of using it ... Thank you.

Quote:
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 ...
__________________
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things.
Reply With Quote
Old 13th July 2008
bsdnewbie999 bsdnewbie999 is offline
Package Pilot
 
Join Date: May 2008
Posts: 145
Default

Besides shell script, is there other programming language that run GUI in OpenBSD like C, java...etc ?
Reply With Quote
Old 13th July 2008
Carpetsmoker's Avatar
Carpetsmoker Carpetsmoker is offline
Real Name: Martin
Tcpdump Spy
 
Join Date: Apr 2008
Location: Netherlands
Posts: 2,243
Default

Yes, just about any programming language can (Including C and Java).
__________________
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things.
Reply With Quote
Old 13th July 2008
ocicat ocicat is offline
Administrator
 
Join Date: Apr 2008
Posts: 3,318
Default

Quote:
Originally Posted by bsdnewbie999 View Post
Besides shell script, is there other programming language that run GUI in OpenBSD like C, java...etc ?
  • Java Swing
  • Python/wxPython
  • Perl/TK
Reply With Quote
Old 13th July 2008
TerryP's Avatar
TerryP TerryP is offline
Arp Constable
 
Join Date: May 2008
Location: USofA
Posts: 1,547
Default

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.
__________________
My Journal

Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''.
Reply With Quote
Old 13th July 2008
BSDfan666 BSDfan666 is offline
Real Name: N/A, this is the interweb.
Banned
 
Join Date: Apr 2008
Location: Ontario, Canada
Posts: 2,223
Default

Why hasn't anyone mentioned the curses library?
Reply With Quote
Old 13th July 2008
18Googol2's Avatar
18Googol2 18Googol2 is offline
Real Name: whoami
Spam Deminer
 
Join Date: Apr 2008
Location: pwd
Posts: 283
Default

Quote:
Originally Posted by BSDfan666 View Post
Why hasn't anyone mentioned the curses library?
Its not GUI, it is still text based
Reply With Quote
Old 13th July 2008
BSDfan666 BSDfan666 is offline
Real Name: N/A, this is the interweb.
Banned
 
Join Date: Apr 2008
Location: Ontario, Canada
Posts: 2,223
Default

Quote:
Originally Posted by 18Googol2 View Post
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.
Reply With Quote
Old 13th July 2008
Carpetsmoker's Avatar
Carpetsmoker Carpetsmoker is offline
Real Name: Martin
Tcpdump Spy
 
Join Date: Apr 2008
Location: Netherlands
Posts: 2,243
Default

Text user interface
__________________
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things.
Reply With Quote
Old 13th July 2008
BSDfan666 BSDfan666 is offline
Real Name: N/A, this is the interweb.
Banned
 
Join Date: Apr 2008
Location: Ontario, Canada
Posts: 2,223
Default

Fuck tradition, I can think for my self, it's a GUI.
Reply With Quote
Reply

Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script with zenity bsdnewbie999 OpenBSD General 5 24th April 2009 02:37 AM
shell script-start another process bsdnewbie999 Programming 2 23rd April 2009 07:48 PM
shell script compare md5 sum bsdnewbie999 Programming 1 11th April 2009 02:20 PM
incrementing within a shell script? spiderpig Programming 5 29th September 2008 08:12 PM
shell script with input c0mrade Programming 5 13th July 2008 04:33 AM


All times are GMT. The time now is 03:30 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick