Using programs to open files from within the script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using programs to open files from within the script?
# 1  
Old 02-14-2012
Using programs to open files from within the script?

I am suppose to make a program that cuts the extension off of a file. It uses that .ext to decide which program needs to be used to open the file. This only finds the name of the program from a list of programs I made. My problem is when it has the name of the program it needs to use, how can I make the program open the file with code in the script.

It is okay to assume that files will only have one period.

Code so far:

Code:
#!/usr/bin/bash -x

FNAME=$1
export FNAME
FILE_EXTENSION=`echo $FNAME | cut -f2 -d "."`

a=`grep $FILE_EXTENSION dorc.sh`
echo $a
PROG=`echo $a | cut -f5 -d "/"`

Moderator's Comments:
Mod Comment Use code tags, see PM.

Last edited by zaxxon; 02-14-2012 at 08:29 PM.. Reason: code tags
# 2  
Old 02-15-2012
This sounds like homework -- we have a special forums for that.
Assume your input file of associations (files.txt) is setup like this
Code:
.lis  vi
.txt vi
.pdf pdf2txt

then try this:
Code:
#!/bin/bash
fname="$1"
suffix= "."${fname##*.}
program2run=$( grep -F "$suffix" files.txt | awk '{print $2}' )
$program2run $fname

This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 02-15-2012
The part I got was the homework to just cut the ext and make it pick a program. I wanted to learn how to go further and make it open the program. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Difference between inbuilt suid programs and user defined root suid programs under bash shell?

Hey guys, Suppose i run passwd via bash shell. It is a suid program, which temporarily runs as root(owner) and modifies the user entries. However, when i write a C file and give 4755 permission and root ownership to the 'a.out' file , it doesn't run as root in bash shell. I verified this by... (2 Replies)
Discussion started by: syncmaster
2 Replies

2. Shell Programming and Scripting

Script to open files and write into new one

Hello! I am a real beginner in scripting, so I am struggling with a really easy task! I want to write a script to concatenate several text files onto each other and generate a new file. I wanted the first argument to be the name of the new file, so: ./my_script.sh new_file file1.txt... (5 Replies)
Discussion started by: malajedala
5 Replies

3. What is on Your Mind?

How safe is Dropbox and Ubuntu one? Would you store critical files or programs there? Any comments o

How safe is Dropbox and Ubuntu one? Would you store critical files or programs there? Any comments on the guarantee that the two companies provide and on the technology used for encryption? (1 Reply)
Discussion started by: frad
1 Replies

4. Cybersecurity

WebApp secure access to protected files/programs

Hello, I'm working on an embedded linux project that provides a devices that uses an IPSec VPN (using racoon) to connect back to base. The device also hosts a WebApp that allows admin users to change many aspect of the networking setup, including things like the VPN pre-shared-key, IP addresses... (1 Reply)
Discussion started by: salukibob
1 Replies

5. UNIX and Linux Applications

Showing all open programs on your bottom toolbar

http://i255.photobucket.com/albums/hh133/COKEDUDEUSF/toolbar.jpg Take a look at my picture to understand what I'm talking about. I have a bunch of programs open right now and I can't see the name of the programs on my toolbar. Is there hopefully a way to see all open programs on your toolbar... (1 Reply)
Discussion started by: cokedude
1 Replies

6. Shell Programming and Scripting

Help with script to open and compare csv files

We are testing an application that accesses two tables: A and B. I am to write a script to validate the ouput files of this application.The application marks any account that has become overdue as per rule. When it runs, it updates the overdue flag in the A table according to the following rules: ... (1 Reply)
Discussion started by: inkyponky
1 Replies

7. Shell Programming and Scripting

open 2 files and compare values script - urgent

Hi gurus I have two csv files that are outputs. The file contains data similar to s.no,number1,number2,date1 -------------------------------- 1, a123,482.29,11/28/07 13:00 2,a124,602.7,9/24/07 14:00 3,a125,266.93,10/9/07 16.48 4,a126,785.15,11/14/07 16:08 <file 2> s.no name... (2 Replies)
Discussion started by: inkyponky
2 Replies

8. UNIX for Dummies Questions & Answers

Are programs like sys_open( ) ,sys_read( ) et al examples of system level programs ?

Are the programs written on schedulers ,thread library , process management, memory management, et al called systems programs ? How are they different from the programs that implement functions like open() , printf() , scanf() , read() .. they have a prefix sys_open, sys_close, sys_read etc , right... (1 Reply)
Discussion started by: vishwamitra
1 Replies

9. UNIX for Dummies Questions & Answers

script that will list .c programs

hey, im trying to write a script that will list all the .c files, and give me the first 10 lines of code in them. I think ive got that bit working, but i want to make it use friendly so i can select whether i want to modify a .c file or delete it. (7 Replies)
Discussion started by: Saggas
7 Replies

10. UNIX for Dummies Questions & Answers

?script/cmds 2 list open files????

I would like to have the commands or a scripts that will show me files that are not open by any process and meet a certain pattern (ie arch.log1_117512.dbf). Basically I a wanting to delete all arched redo logs that oracle has popped out execpt for the current one it is writting to. I am... (3 Replies)
Discussion started by: bn80865
3 Replies
Login or Register to Ask a Question