I am trying to create a script to run vlc to play (or queue if a playlist is already present) some videos.

so far in my ~/bin/ folder I have created a file ``myvlc'' with the following command:

#!/usr/bin/env bash
vlc --http-port 54444 %U

This works as a command if I set it as launcher command in an icon, but it doesnt work if from the command line I type: myvlc ~/Videos/Some\ Folder/video.avi

How can I modify this bash script and make it work?


Suggestion: use Bash aliases

Aliases allow you to append more arguments and 'overrule' current commands too. For example, this alias:

alias hvlc='vlc --http-port 54444'

will make

hvlc -v /path/to/my/movie.mkv

to become

vlc --http-port 54444 -v /path/to/my/movie.mkv

If you like the alias, install it permanently:

echo "alias hvlc='vlc --http-port 54444'" >> ~/.bash_aliases

The default ~/.bashrc file installed for users in Ubuntu will source the ~/.bash_aliases file by default.

More about aliases in an earlier answer of me.

About your script

It's not passing the arguments to the vlc command as given to the "parent" Bash script. To fix this, make the line

vlc --http-port 54444 $@

The $@ is the Bash magic for "all arguments". The %U is only used in .desktop files in GUIs and is a magic string to place the URL to be opened.

  • thanks your answer has been really helpful! Since you were kind enough to send me a link for aliases, do you have any clear tutorial for bash scripting as well? – lucacerone Jan 30 '13 at 19:05
  • ok the script works fine now thanks! Now how can I make it the default to be used when opening a video file? – lucacerone Jan 30 '13 at 19:09

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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