LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-25-2017, 12:37 AM   #1
timl
Member
 
Registered: Jan 2009
Location: Sydney, Australia
Distribution: Fedora,CentOS
Posts: 750

Rep: Reputation: 156Reputation: 156
pass arguments to script using symbol


Hi, there are several shows on BBC radio which I grab on Sunday using get_iplayer. My process is:
  1. use a script to "get" the latest schedule and dump in a file
  2. search the schedule for the latest episode of the show I want
  3. use another script to record the show
As there are 4 or 5 I get on a Sunday I was thinking of automating the process. My knowledge of awk/sed is non-existent but I thought I would be able to cobble something together. The first step is to search the file and then drag out the show number to a symbol. This bit works and I can echo back the command successfully. However when I pass the symbol to the script I get an error. I get the feeling that the name of the symbol is being passed to the script however echo contradicts that thought. I would be interested to know the correct way to pass a parameter to a script when the parameter is in the form of a symbol?

Cheers

Quote:
[tim@Vampyre ~]$ cat Documents/dgett
#!/bin/bash
#
# get ID passed in $1 from iplayer
#
cd /home/tim
get_iplayer "$1" --get --aactomp3 --radiomode=better

[tim@Vampyre ~]$ grep -i "beat surrender" bbcr | tail -1 > abc

[tim@Vampyre ~]$ cat abc
13546: Beat Surrender - 18/02/2017, BBC Newcastle, p04rjqvc

[tim@Vampyre ~]$ xxx=$(awk '{print $1}' abc)

[tim@Vampyre ~]$ echo dgett $xxx
dgett 13546:

[tim@Vampyre ~]$ dgett $xxx
get_iplayer v2.97, Copyright (C) 2008-2010 Phil Lewis
This program comes with ABSOLUTELY NO WARRANTY; for details use --warranty.
This is free software, and you are welcome to redistribute it under certain
conditions; use --conditions for details.


INFO: 0 Matching Programmes

[tim@Vampyre ~]$ dgett 13546
get_iplayer v2.97, Copyright (C) 2008-2010 Phil Lewis
This program comes with ABSOLUTELY NO WARRANTY; for details use --warranty.
This is free software, and you are welcome to redistribute it under certain
conditions; use --conditions for details.

Matches:
13546: radio, Beat Surrender - 18/02/2017, BBC Newcastle, p04rjqvc

INFO: 1 Matching Programmes
INFO: Beat Surrender - 439. 18/02/2017 (p04rjqvc) Already in history (/home/tim/.get_iplayer/download_history) - use --force to override
 
Old 02-25-2017, 01:28 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,308
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
There are a lot of refinements you could make but I think the first one would be to make use of awk's ability to use patterns for field separators. If colons don't show up anywhere else, then you could do it like this:

Code:
awk -F '[ :]' '{print $1}'
Otherwise, you'll just have to trim the first field of any punctuation:

Code:
awk '{ sub(/[[:punct:]]/, "", $1); print $1 }'
Eventually you'll be able to put the equivalent of grep and tail in there too. But one change at a time for now.
 
1 members found this post helpful.
Old 02-25-2017, 08:42 AM   #3
ilainftw
LQ Newbie
 
Registered: Feb 2016
Posts: 4

Rep: Reputation: Disabled
You don't need to go to such lengths unless you're using this as an exercise to learn something about awk or scripting in general. get_iplayer can do all the work for you with its PVR capability.
 
1 members found this post helpful.
Old 02-26-2017, 03:36 AM   #4
timl
Member
 
Registered: Jan 2009
Location: Sydney, Australia
Distribution: Fedora,CentOS
Posts: 750

Original Poster
Rep: Reputation: 156Reputation: 156
Hi guys and thanks for the feedback. As well as making my life easier this was an exercise in using awk and turbo has opened my eyes to some of the possibilities. I was not aware of the PVR options but I had a look at the man page and I have a better idea now. I shall start tinkering.

Thanks again
 
Old 03-08-2017, 12:32 AM   #5
timl
Member
 
Registered: Jan 2009
Location: Sydney, Australia
Distribution: Fedora,CentOS
Posts: 750

Original Poster
Rep: Reputation: 156Reputation: 156
thanks to all. I have now got a solution to my query albeit in a roundabout way. Thanks to turbo for putting my mind straight on how to think laterally and thanks to ilainftw for recommending the pvr options which I now understood and put to use.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
wrapper script using getopts to pass all arguments except one threezerous Linux - Newbie 1 04-14-2014 06:08 PM
How to pass command line arguments from one shell script to another shell script VijayaRaghavanLakshman Linux - Newbie 5 01-20-2012 09:12 PM
How to pass all arguments to a function stormcloud Linux - General 4 07-08-2010 03:15 AM
How to pass arguments in a shell script? Drigo Linux - Newbie 1 11-14-2009 11:55 AM
How to pass arguments from $prompt for php script ukjairaj Linux - Software 4 06-25-2004 11:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:21 PM.

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