From: Theo v. Werkhoven on 14 Apr 2010 15:37 The carbonbased lifeform houghi inspired comp.unix.shell with: > Bill Marcum wrote: >> On 2010-04-09, houghi <houghi(a)houghi.org.invalid> wrote: >>> I have the following script: >>> #v+ >>> #!/bin/bash >>> set -x >>> COUNT=0 >>> youtube-dl -g -e -b $URL |while read LINE >>> do >>> if [ "$COUNT" == "0" ] >>> then >>> TITLE=$LINE >>> COUNT=1 >>> else >>> LINK=$LINE >>> echo $LINK >>> fi >>> done >>> echo ${TITLE}.flv >>> echo $LINK >>> #v- >>> >>> >>> My question is why does it do the echo with the first $LINK but not with >>> the second? As far as I can see LINK gets a value (as well as TITLE), >>> yet at the end they are somehow empty. What am I doing wrong? >>> >> The loop is in a pipe, so it's in a subshell. > > So what is the solution? I could write the values to a temporary file, > but I like to avoid that. So the obvious solution would be not to use a > pipe. > > What I actualy want is the following: `youtube-dl -g -e -b $URL` gives > me output in two lines. The first line will have a lot of spaces in it. > $TITLE should get that value. The second line won't have any spaces in > it. $LINK should get that value. Have you thought of using something differnt than shell script? E.g., in Python: #v+ >>> from commands import getoutput >>> URL = "http://www.youtube.com/watch?v=qkUzITnV3rA" >>> Title, Link = getoutput("/usr/bin/youtube-dl -g -e -b " + URL).split('\n') >>> Title 'Rihanna Vs UB 40 - Rude Boy Vs Kingston Town (Djs From Mars Bootleg Remix)' >>> Link 'http://v9.lscache4.c.youtube.com/videoplayback?ip=0.0.0.0&sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Calgorithm%2Cburst%2Cfactor%2Coc%3AU0dWRlJUVF9FSkNNNl9KTlhJ&algorithm=throttle-factor&itag=35&ipbits=0&burst=40&sver=3&expire=1271296800&key=yt1&signature=19D1054A716230623E45D0109515CA5099F26ED9.C50B835B55EB4729832296E438C5D17BD88F529A&factor=1.25&id=aa45332139d5deb0' #v- No need for loops, sub-shells or if..thens Theo -- theo at van-werkhoven.nl ICQ:277217131 SuSE Linux linuxcounter.org: 99872 Jabber:muadib at jabber.xs4all.nl AMD XP3000+ 1024MB "ik _heb_ niets tegen Microsoft, ik heb iets tegen de uitwassen *van* Microsoft"
First
|
Prev
|
Pages: 1 2 3 4 5 6 Prev: Change Case of Word Using VI Next: adding a user twice to solaris os |