Originally Posted by 111
basically what I'm trying to do is create a function or script of some sort that would simplify writing out various parameters such as "viewCount" and use a single letter instead like "v". Also it would allow for parameter combinations that would otherwise have to be written in numerous alias/functions.
alias ylv='youtube-viewer --duration=long --orderby=viewCount'
alias ysr='youtube-viewer --duration=short --orderby=rating'
again like I say each of these could just be written out as an alias/function - and this is how I've done it so far but there should be another way to do this.
I know this explanation sounds confusing, but this the best way I can describe it.
about variables - they seem to be listed in all the bash programming guides, but I guess that may not even pertain to this situation.
also please note I have very little knowledge of scripting at this point.
and yes the "function" spelling was a typo.
function yv ()
youtube-viewer --orderby="$1" --author="$2"
I think I understand, maybe ( CH3CH2OH )
Above is your original, ( mostly for me to see while I type )
You want a command that you can type like this
First reason that ain't going to work is .. I don't do YouTube
The shell has executed this;
youtube-viewer --orderby="v" --author="Firerat"
Do you see what happened?
yv v Firerat
cmd $1 $2
This probably fits better
function yv ()
case $1 in
*) echo "Ehh? wtf Yow want?"
echo "Valid options are :"
echo "p, r and v"
echo "You work out what they mean11"
exit 234 # document 234 to be user screwed up;;
# esac is case backwards ( and I still hate typing it )
youtube-viewer --orderby="$Orderby" --author="$Author"
Now, this ain't perfect by any standard
But it will do what you want ( I hope, not tested )
case is really best suited to when you need lots of nested if, else
But as you can see can be used to make a basic Option processor
getopt will be of interest
and case can be more elaborate than the above example
To be honest, I would probably stick something like that into its own standalone script ( in ~/bin/ for example )
And I would Name it a little more descriptive,
YouTubeViewer, yesh I know what that is and does.
by the time you have typed
you will have probably finished it already
( look up tab completion )