The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Correct me to run a sh file in ksh shell! trantuananh24hg SUN Solaris 4 06-10-2008 06:01 PM
Book review: Open iPhone Application Development iBot UNIX and Linux RSS News 0 06-03-2008 01:40 PM
Correct format in a log file sd12 UNIX for Advanced & Expert Users 11 12-12-2007 02:40 PM
Computing: Free Application Software and Open Data Standards (Part 3) - Amerisurv (pr iBot UNIX and Linux RSS News 0 06-18-2007 11:10 AM
Which application has a TCP socket open murphyboy UNIX for Dummies Questions & Answers 3 10-26-2005 02:29 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-02-2008
Registered User
 

Join Date: Feb 2008
Posts: 3
Stumble this Post!
Open file with correct application

Can someone please help me with my bourne shell script. I am a struggling newbie. I need create a script that will read an argument from a command line, access a config file with application file types, and open the file with the correct application. The file needs to be able to handle file extensions like .c or .h and exceptions. My config looks like:

#This is a sample .dorc

Application/PostScript ps /usr/bin/ggv

and my current shell script:

#!/usr/bin/bash

filename=$(basename ${1})
echo $1
file_ext=${filename##*.}
echo $file_ext
line=$(grep $file_ext sample.dorc | cut -f3 $i)
$line $1

Thanks in advance for any help.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-02-2008
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,430
Stumble this Post!
Not sure what you're looking for really, but he is my rewrite with an error check...
Code:
#!/usr/local/bin/bash
file_ext=${1##*.}
echo $file_ext
prog=$(awk -v ext=$file_ext '$2 == ext {print $3}' sample.dorc)
if [[ -n $prog ]] ; then
        echo $prog can run $1
else
        echo $1 not configured in dorc file
fi
exit 0
Reply With Quote
  #3 (permalink)  
Old 02-02-2008
Registered User
 

Join Date: Feb 2008
Posts: 3
Stumble this Post!
Thanks for you reply

Thanks for your help. I tried your re-write but it gave me a command not found error. I'm sure I made a mistake somewhere. I'm really new at this. The purpose of my script is to basically perform the same functionality as a double click in windows. If I double click on a word file it opens in MS Word. My script should take the filename in the command line and open it with the correct application. I appreciate the help.
Reply With Quote
  #4 (permalink)  
Old 02-03-2008
Registered User
 

Join Date: Feb 2008
Posts: 3
Stumble this Post!
Still not working

I still cannot get my script to work correctly. Additional help would be greatly appreciated. Should I use an awk command?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:03 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0