0

I am trying to open various tab at the same time using xdg-open my default browser is firefox.

The following line works (for one tab):

xdg-open https://stackoverflow.com

But this one does not:

xdg-open https://stackoverflow.com https://google.fr

the error thrown is:

xdg-open: unexpected argument 'https://google.fr'

Isn't it any way of passing various URL to xdg-open? Thanks in advance !

Ced
  • 853
  • 4
  • 13
  • 33

2 Answers2

4

This is not possible with xdg-open alone because it expects exactly one argument. But you can write a function to iterate over all given arguments and call xdg-open separately.

Open your ~/.bashrc file in an editor, e.g.

gedit ~/.bashrc

and then add the following text at the end of the file:

xo () 
{ 
    for var in "$@"; do
        xdg-open "$var";
    done
}

Save the file and leave the editor. After that either close and re-open the terminal window or enter

source ~/.bashrc

in the current window for the change to take effect. From now on you have a new command xo and can issue

xo https://stackoverflow.com https://google.fr

See also my answer to the slightly related question Shorten or merge multiple lines of &> /dev/null &.

PerlDuck
  • 13,885
1

A simple open function to open file/url (multiple) and the new application disown to the terminal

#!/bin/bash
function openn() {
  if [ "$#" -lt 1 ]; then
    echo "You must enter 1 or more command line arguments";
  elif [ "$#" -eq 1 ]; then
    xdg-open "$1" > /dev/null & disown;
  else
    for file in "$@"; do
      xdg-open "$file" > /dev/null & disown;
    done
  fi
}