Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 11-24-2005, 01:29 PM   #1
LQ Newbie
Registered: Aug 2003
Location: Funchal, Portugal
Distribution: Fedora 14
Posts: 8

Rep: Reputation: 0
help on shell script as a wrapper to launch default programs according to input file


I'm using marvellous program Freemind, see, everyone should find this program useful for lots of daily tasks!

It's a Java program and it allows us to launch an external program where the first parameter is a path of a file. In Linux it defaults to konqueror which is not good to open files like documents or Adobe PDFs in a user-friendly way, since I'm using Gnome as default desktop.

So I thought on using a shell script to parse the file received, detect the file extension and then launch the corresponding program.

I have very little experience on shell scripting so I ask for help on how to do this.

The script receives a path with this format:


So the script will have to extract what's on the right of : (this I already think it's working)

Then it will have some kind of WHILE command to go trough the string to find the extension, save it in some variable, then have something like a CASE that for predefined extension types will then launch the corresponding program.

Here's what I got until now:


PATH=`echo $1 | awk -F'file:' '{print $2;}'`
But it's not working

I try this

fmlaunch file:/home/david/actual/academico/Phd/bibliografia/function/bickhard/ErrorDynamics.pdf
and I get this:

/usr/bin/acroread: line 8: ls: command not found
/usr/bin/acroread: line 8: sed: command not found
/usr/bin/acroread: line 9: dirname: command not found
/usr/bin/acroread: line 17: dirname: command not found
/usr/bin/acroread: line 102: dirname: command not found
/usr/bin/acroread: line 109: dirname: command not found
/usr/bin/acroread: line 117: ls: command not found
/usr/bin/acroread: line 117: sed: command not found
/usr/bin/acroread: line 118: expr: command not found
ERROR: Cannot find installation directory.
I wonder if it's because acroread is also a script?
Old 11-24-2005, 04:08 PM   #2
Registered: Nov 2003
Location: Belgium
Distribution: Slackware
Posts: 184

Rep: Reputation: 26

FILEPATH=$(echo $1 | sed 's/^file://')
EXTENSION=$(echo 1 | sed 's/.*\.//g')

case "$EXTENSION" in
xmessage -buttons 'ok:1' "unknown type $FILEPATH"

use double quotes for variables that can contain spaces (even better don't use spaces
in a file or directory name at all)

and don't use PATH since it can block other scripts if you use it with export, also it makes the script less readable


Old 11-24-2005, 04:20 PM   #3
LQ Newbie
Registered: Aug 2003
Location: Funchal, Portugal
Distribution: Fedora 14
Posts: 8

Original Poster
Rep: Reputation: 0
Thank you for your help on the script!
On the second echo you forgot a dollar sign right?

Meanwhile I found another alternative, one just needs to use the command


in Freemind prefs and Gnome automagically opens the default app for the file tha I clicked in Freemind.


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
Shell script pipe input - bash mostly laikos Programming 4 11-09-2008 05:14 PM
how can I take input with a shell script? GUIPenguin Linux - General 4 04-11-2005 03:46 PM
Shell script user input tuckermaddox Linux - Newbie 5 08-12-2004 03:14 AM
Opening file with default application from shell script? bourbon_beast Programming 4 04-13-2004 01:52 AM
can't launch java app from shell script... LonAllen Linux - Newbie 0 07-07-2003 08:37 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:52 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration