Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Suppose I want to associate PPT files to be opened with a bash script that converts it to PDF then opens it with the approperiate PDF editor. How do I do that?

Conversion will be done with uniconv as I learnt from another question

uniconv -f pdf presentation.odt

I believe I have to change "presentation.odt" with the filename that triggered this script

share|improve this question
1  
You might get more answers (or better answers) on the Unix and Linux stackexchange or on Stackoverflow. –  Kris Harper Aug 21 '11 at 3:18

3 Answers 3

up vote 4 down vote accepted

Do you mean that the script will be called with (for example) presentation.odt as an argument? The argument is available as "$1" in the script (the double quotes are required if the file name contains characters like spaces which the shell would otherwise expand). You can construct the name of the PDF file by stripping away the .odt suffix: ${1%.odt}. Note that it's unoconv, not the unrelated uniconv.

#!/bin/sh
unoconv -f pdf "$1"
appropriate-pdf-editor "${1%.odt}.pdf"
share|improve this answer
1  
appropriate-pdf-editor could be xdg-open to use whichever pdf viewer is currently set as default. –  geirha Aug 21 '11 at 13:43

In a shell script, you can access command line parameters through the variable 1, 2, 3, ..., as in

#!/bin/bash

echo "$1"
echo "$2"
echo "$3"
# ...

If you need it, "$0" represents the script name itself.

You can also reassign these variable, and shift them, to access more than 9 parameters.

share|improve this answer

If you want to find all .odt files and feed them into unoconv, you can use the find tool to find all of them, then pipe it into xargs, which can do parallel processing.

find * -type f -iname "*.odt" | xargs -i -P12 "uniconv -f pdf {}"

This will find all files in the running directory, recurssively, piping files that it finds into xargs, which will run up to 12 processes silmultaneously (use -P0 for unlimited processes).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.