Specifying a variable without editing my script everytime
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Specifying a variable without editing my script everytime
(1 of Several very recent, semi-related posts in a series to record/watch tv)
Hi, I haven't really liked any of the applications I've found for recording tv with linux, either they don't have options I desire, they are too slow, they require specific applications I do not wish to use or just something I don't like about em... So I am trying to eventually be able to just open up a terminal and type something like:
mentv 16
and have a script I've created called mentv start recording channel 16 (using mencoder) until I hit ctrl+c
Here is the script (no, I am not kidding, I just don't know scripting that well, or rather, at all )
And so I'd like to somehow make:
channel=16
be a variable that recieves it's input from me after running the script, as shown above with:
$mentv 12
to record channel 12.
I haven't even the slightest idea of where to start, so if anyone has any ideas I'd greatly appreciate it.
#!/bin/bash
while getopts hc: OPT; do case "$OPT" in
c) channel="$OPTARG"; printf "You choose channel $OPTARG\n";;
h) printf "%sUsage: $0 -c <channel>.\n"; exit 1;; esac; done;
case "${#channel}" in 0) exit 1;; esac
mencoder -tv on:chanlist=us-cable:channel=${channel}\
etc etc.
And it works
mentv 13, now records from channel 13 for me, mentv 14 from 14 and so on..
Thank you for the suggestion!
Quote:
[Originally posted by UnSpawn How about using "getopts" using "-c <channel>":
#!/bin/bash
while getopts hc: OPT; do case "$OPT" in
c) channel="$OPTARG"; printf "You choose channel $OPTARG\n";;
h) printf "%sUsage: $0 -c <channel>.\n"; exit 1;; esac; done;
case "${#channel}" in 0) exit 1;; esac
mencoder -tv on:chanlist=us-cable:channel=${channel}\
etc etc.
I decided to give this a try as well, just to see what the outcome would be like, however I don't know if I compiled getopts correctly, or what the problem was, but I would just get returned to the prompt with no error. I compiled getopts by:
gcc main.c getopts.c -o getopts
And then copied the a.out (renamed getopts from -o getopts) to /usr/local/bin
Thank you anyway for your suggestion it intreagued me very much, helped me learn a few things about compiling along the way!
Quote:
Originally posted by acid_kewpie nb. channels= and channel= vairables are not compatible with each other afaik.
Thank you for that as well, that must have been my error since it's working great now.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.