2

I would like to open multiple instances of the same file with some sort of command. I've tried some very unsophisticated ideas (e.g., an alias or function in my .bashrc, a simple shell script), but they all open the file once, then open another instance after i close the first open file).

I know it's not a big deal to simply type an aliased command four (say) times, but it must be dead easy to write a command that would call, e.g.,

mupdf /path/to/file/file.pdf

four times so the file is opened four times all at once..?

2 Answers 2

4

It sounds like that your approach is using sequential invokation of the commands. You need to start the programs in the background. In bash (use your own program instead of the fictional 'openpdf'):

$ openpdf something.pdf &
[1] 1234
$

The & symbol tells bash to launch the program in the background. You can type in other commands while the other program is running. If you repeat this n times then it will be launched n times. Learn more about job control in bash by consulting the manual.

2
  • I'll be damned. I could've sworn that's what I did yesterday, but I must only tried && and ;. I feel like a fool, but thanks anyway!
    – jon
    Feb 7, 2012 at 16:08
  • I should also add (in case anyone else makes the same mistake) that not all pdf viewers like opening multiple copies of the same file (e.g., evince).
    – jon
    Feb 7, 2012 at 16:43
1

To open it 3 times, call it like this:

   for i in {1..3}; do xpdf some.pdf & done

An alias will not work for the general case, since you have 3 parameters, and aliases don't allow for parameters:

  • N the number of times to run
  • prg the program to run
  • file the file to open with the program

So you could write a function to include in your .bashrc:

 #!/bin/bash
 xtimes () {
     for i in $(seq 1 $1); do $2 $3 & done
 }

You can't use {1..$1}, because in curly braces, there is no parameters expansion.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .