Open file with correct application


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Open file with correct application
# 1  
Old 02-02-2008
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.
# 2  
Old 02-02-2008
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

# 3  
Old 02-02-2008
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.
# 4  
Old 02-03-2008
Still not working

I still cannot get my script to work correctly. Additional help would be greatly appreciated. Should I use an awk command?
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

After Ftp'ing file to destination how to check the file if it is in correct ASCII and not corrupted

Hi Folks, While transferring file from FTP software like Filezilla the files gets corrupted. Is there any way I can check if the recently transferred file is in ASCII and not corrupted. I have tried using file -i filename command which does tell if the file character set is ASCII or binary... (6 Replies)
Discussion started by: Khan28
6 Replies

2. Shell Programming and Scripting

Automatically correct a File Name

Hi All Need a help to understand how one can automatically correct a file name using a shell script even if it is in a completely different format... Ex : adv_OK_0215_mem_rules_firing.txt / advex_0215_OK_me_rule_fire.txt (or in any other format as above) to :... (13 Replies)
Discussion started by: chatwithsaurav
13 Replies

3. Shell Programming and Scripting

open application with spaces in name [bash][OSX]

Hi guys, I'm new here and new to shell scripting so don't be hard on me I'm trying to create a bash script to restart a process by name in Mac OSX. I have no problem killing the application, the problem comes when launching it again. I managed to store the path in a variable lets say ... (8 Replies)
Discussion started by: jonathanwiesel
8 Replies

4. Red Hat

cannot set user id: Resource temporarily unavailable (not open file/open process related)

First post, sorry to be a bother but this one has been dogging me. I have a process user (java application server) that trips a resource limit every couple weeks and need help finding what limit we're hitting. First, this is what's running: This is the error when jobs are run or the... (0 Replies)
Discussion started by: Katahdin
0 Replies

5. Programming

How to get the correct exception file/line.

The below code throws error in the line number 32 where the function is defined. But How to find the line where the function is called. That is I want to throw the error at the line number 43 (as here the function is called). The code is: #include <iostream> #include <string>... (9 Replies)
Discussion started by: SamRoj
9 Replies

6. OS X (Apple)

Check for open application

Hi there, Is there any command to check if a particular application is open on a mac? thanks :) (3 Replies)
Discussion started by: davewg
3 Replies

7. UNIX for Advanced & Expert Users

Correct format in a log file

I'm trying to read the output of a .sql script (simple insert and commit oracle pl/slq script) to a log file using a shell script. My problem is I end up with a log file that looks like this: sd12@phenix97:/detain/sd12/logs > cat 20071205_detain_20071206.log 12320496 rows created. Commit... (11 Replies)
Discussion started by: sd12
11 Replies

8. UNIX for Dummies Questions & Answers

Which application has a TCP socket open

If I do a netstat -a I can see all the sockets currently open, is there a way that I can tell which application is holding open these sockets ? (3 Replies)
Discussion started by: murphyboy
3 Replies
Login or Register to Ask a Question