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:

#!/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 "/"`

This sounds like homework -- we have a special forums for that.
Assume your input file of associations (files.txt) is setup like this

.lis  vi
.txt vi
.pdf pdf2txt

then try this:

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

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. :slight_smile: