You are not logged in.

#1 2012-02-05 11:59:27

Jindur
Member
Registered: 2011-09-29
Posts: 184

[SOLVED] A small problem with command-line arguments

whenever I call VLC I want to add a parameter by default, namely

--codec crystalhd

.
So what I did is renamed the VLC binary to vlc.2.1.0 and added a shell script 'vlc' instead that calls it.

It just looks like this:

#!/bin/bash
vlc.2.1.0 --codec crystalhd $*

The problem however is that this will cause vlc to throw an error when the filename contains spaces!
So next I tried this modification of above script:

#!/bin/bash
vlc.2.1.0 --codec crystalhd "$*"

Indeed this works again since the filename will be enclosed in quotes, however now a new problem arises:
If the script itself is called with additional parameters besides the filename, those will also be placed into those quotes, which of course won't work! Eg:

$ vlc --parm x file\ name\ with\ spaces

will obviously call:

vlc.2.1.0 --codec crystalhd "--parm x file name with spaces"

Isn't there a way to just simply pass the string of command-line arguments AS IS directly to the vlc.2.1.0 call without need for quotes or processing being done on its escape sequences or anything?
Any help appreciated.

Last edited by Jindur (2012-03-01 14:19:26)

Offline

#2 2012-02-05 12:10:07

Vain
Member
Registered: 2008-10-19
Posts: 174
Website

Re: [SOLVED] A small problem with command-line arguments

Hi,

you should use "$@" instead of "$*" (and not "*$", btw). And don’t forget the quotes. smile

See also: http://www.gnu.org/software/bash/manual … Parameters

Offline

#3 2012-02-05 12:17:43

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 13,992
Website

Re: [SOLVED] A small problem with command-line arguments

Is there a reason for a script rather than an alias?

#in bashrc
alias vlc='vlc --codec crystalhd'

This is much cleaner, and will not be broken by every update of vlc,


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Offline

#4 2012-02-05 12:32:53

Jindur
Member
Registered: 2011-09-29
Posts: 184

Re: [SOLVED] A small problem with command-line arguments

Awesome, thanks guys. Well I'm not that familiar with bash script as you can see. Actually I know about aliases (using some for extended 'ls') but didn't think of it at all here, probably due to lack of routine I guess. ^^'

Offline

#5 2012-02-05 13:57:39

karol
Archivist
Registered: 2009-05-06
Posts: 25,430

Re: [SOLVED] A small problem with command-line arguments

Please remember to mark the thread as solved :-)

Offline

Board footer

Powered by FluxBB