LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-07-2005, 09:27 PM   #1
deepsix
Member
 
Registered: Apr 2003
Distribution: ANY
Posts: 339

Rep: Reputation: 32
scripting help please


i want to write a script that allows me to type the following at the command line and acheive the following results

umpitysquat@linux: open big_kitty.jpg and it open big_kitty .jpg with gqview
or
umpitysquat@linux: open tig_bitties.mpg and it open tig_bitties.mpg with mplayer
also
umpitysquat@linux: open resume.txt and it open resume.txt with an editor........

i have limited scripting knowlege..........
any info or related links would be appreciated.
 
Old 09-07-2005, 09:38 PM   #2
deepsix
Member
 
Registered: Apr 2003
Distribution: ANY
Posts: 339

Original Poster
Rep: Reputation: 32
Re: scripting help please

Quote:
Originally posted by deepsix
i want to write a script that allows me to type the following at the command line and acheive the following results

umpitysquat@linux: open big_kitty.jpg and it open big_kitty .jpg with gqview
or
umpitysquat@linux: open tig_bitties.mpg and it open tig_bitties.mpg with mplayer
also
umpitysquat@linux: open resume.txt and it open resume.txt with an editor........

i have limited scripting knowlege..........
any info or related links would be appreciated.
or if someone could give me the proper syntax to get a command like mplayer to open a file on the file system that would get me started....

i thought this would work but it didnt.......

#!/bin/bash

mplayer&



chmod a+x open

then type open ziggy.mpg


i also just tried
#!/bin/bash
mplayer

Last edited by deepsix; 09-07-2005 at 09:42 PM.
 
Old 09-07-2005, 09:48 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911
You'd obviously have to tell mplayer WHICH file to play
before you detach it, e.g.:

mplayer snowwhite.avi&

Btw, since gqview is REALLY meant to view
directories full of images as a slide-show I'd
suggest that you use display or xv for pix.






Cheers,
Tink
 
Old 09-07-2005, 09:55 PM   #4
deepsix
Member
 
Registered: Apr 2003
Distribution: ANY
Posts: 339

Original Poster
Rep: Reputation: 32
tks.....for the advice

What im trying to do is have the shell script check the extension of the file that follows it at the command prompt and use the appropriate or designated program to open it.........
 
Old 09-07-2005, 10:10 PM   #5
deepsix
Member
 
Registered: Apr 2003
Distribution: ANY
Posts: 339

Original Poster
Rep: Reputation: 32
GOT IT!.......

or a start at least .........thanks for the help



#!/bin/bash

VIDEO_FILES="ogm mpg mpeg avi mov"
IMAGE_FILES="png jpg gif"

EXTENSION=${1##*.}

if echo $VIDEO_FILES | grep -i $EXTENSION >/dev/null 2>&1
then
echo "Video File"
if [[ -e $1 ]]
then
mplayer $1
fi
elif echo $IMAGE_FILES | grep -i $EXTENSION >/dev/null 2>&1
then
echo "Image File"
if [[ -e $1 ]]
then
eog $1
fi
fi
 
Old 09-08-2005, 12:02 AM   #6
freegianghu
Member
 
Registered: Oct 2004
Location: somewhere in the street
Distribution: Window$
Posts: 192

Rep: Reputation: 30
Too complex
Code:
#!/bin/bash

case $1 in
*.jpg | *.gif | *.bmp)
  exec eog $1
  ;;
*.ogm | *.mpg | *.mpeg | *.avi | *.mov)
  exec mplayer $1
  ;;
esac
 
Old 09-08-2005, 12:27 AM   #7
bhar0761
Member
 
Registered: Jul 2005
Location: San Francisco
Distribution: Fedora Core 6
Posts: 64

Rep: Reputation: 15
wow, that does simplify it. good response
 
Old 09-08-2005, 08:49 AM   #8
deepsix
Member
 
Registered: Apr 2003
Distribution: ANY
Posts: 339

Original Poster
Rep: Reputation: 32
Quote:
Originally posted by freegianghu
Too complex
Code:
#!/bin/bash

case $1 in
*.jpg | *.gif | *.bmp)
  exec eog $1
  ;;
*.ogm | *.mpg | *.mpeg | *.avi | *.mov)
  exec mplayer $1
  ;;
esac

damn good job..........you got a favorite book or reading spot on the web?.........please post links......
thanks again

BTW: whats the difference between case esac , and if fi, if that makes sense?

Last edited by deepsix; 09-08-2005 at 08:51 AM.
 
Old 09-08-2005, 09:57 AM   #9
freegianghu
Member
 
Registered: Oct 2004
Location: somewhere in the street
Distribution: Window$
Posts: 192

Rep: Reputation: 30
Quote:
Originally posted by deepsix
damn good job..........you got a favorite book or reading spot on the web?.........please post links......
thanks again
Code:
man sh
 
Old 09-08-2005, 11:31 AM   #10
bhar0761
Member
 
Registered: Jul 2005
Location: San Francisco
Distribution: Fedora Core 6
Posts: 64

Rep: Reputation: 15
fi closes if
and esac closes case
they are just spelled backwards....

Its kinda like start and end.
 
Old 09-08-2005, 08:49 PM   #11
deepsix
Member
 
Registered: Apr 2003
Distribution: ANY
Posts: 339

Original Poster
Rep: Reputation: 32
sweet ........thanks for all the input
 
  


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
new to scripting mifan Linux - Newbie 2 08-17-2005 01:10 PM
another help with scripting?! ice99 Programming 2 08-09-2005 09:56 AM
Need help scripting Tamara Programming 7 06-06-2005 03:06 AM
Scripting Help Please Jazinator Linux - Newbie 7 10-17-2004 07:35 PM
scripting bforest Linux - Newbie 4 05-11-2004 03:45 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:19 PM.

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