LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-23-2003, 12:30 AM   #1
MasterC
LQ Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu ; CentOS ; Raspbian
Posts: 12,613

Rep: Reputation: 69
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 )
Code:
#!/bin/bash
mencoder -tv on:chanlist=us-cable:channel=16:channels=13-Fox,11-UPN,16-WB,8-Disc:driver=v4l:width=720:height=480:norm=ntsc:forceaudio:amode=1:adevice=/dev/dsp \
-ovc lavc -lavcopts vcodec=mpeg4:vhq:vbitrate=1100 \
-oac mp3lame -lameopts cbr:br=128 -vop scale=512:340,pp=tn/lb -sws 1 \
-o output.avi
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.

Thanks
 
Old 04-23-2003, 02:15 AM   #2
jharris
Senior Member
 
Registered: May 2001
Location: Bristol, UK
Distribution: Slackware, Fedora, RHES
Posts: 2,243

Rep: Reputation: 47
Does the following meet your requires?
Code:
#!/bin/bash

echo "Command line arg 1 = $1"
echo "Command line arg 2 = $2"
Which gave me
Code:
root@tetsuo:~# ./test.sh record 16
Command line arg 1 = record
Command line arg 2 = 16
HTH

Jamie...
 
Old 04-23-2003, 02:35 AM   #3
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,304

Rep: Reputation: 65
tar clfpv - $1 |(cd /$2; tar xpf - --same-owner --atime-preserve)

this is a stupid file copying script i use.
i named it tarcopy. it takes 2 variables from the
command line. source and destination

tarcopy . /work/stuff/

. gets assigned to $1
/work/stuff/ gets assigned to $2
 
Old 04-23-2003, 04:03 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
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.
 
Old 04-23-2003, 06:10 AM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
nb. channels= and channel= vairables are not compatible with each other afaik.
 
Old 04-23-2003, 07:28 PM   #6
MasterC
LQ Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu ; CentOS ; Raspbian
Posts: 12,613

Original Poster
Rep: Reputation: 69
Quote:
Originally posted by jharris
Does the following meet your requires?
Code:
#!/bin/bash

echo "Command line arg 1 = $1"
echo "Command line arg 2 = $2"
Which gave me
Code:
root@tetsuo:~# ./test.sh record 16
Command line arg 1 = record
Command line arg 2 = 16
HTH

Jamie...
Woohoo! Thanks, I just tried a straight forward $1, so now it looks like like this:
Code:
mencoder -tv on:chanlist=us-cable:channel=$1:driver=v4l....
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.



Cool
 
Old 04-23-2003, 08:09 PM   #7
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
]$ type getopts
getopts is a shell builtin

Execute "sh -x <scriptname> -c 16" and you'll see what it should look like.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Script and Dynamic variable xanthium Programming 11 07-12-2011 06:05 AM
variable one script to another rharris72 Programming 2 11-23-2005 01:17 AM
Query about script variable phantomdude Linux - Newbie 1 03-18-2004 11:21 AM
bash script $n variable expansion cortez Programming 6 12-08-2003 04:03 PM
Editing my $PATH variable bml Linux - General 6 03-25-2003 08:14 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration