2

So what this does (currently) is grab how many streamers are live. Let's say 2 of 5 are live, which works fine.

What I'd like to achieve is for those 2 streamers that are live to be "remembered" in a list without having to save it to a document.

So maybe a variable like $ListofStreamers and then I could use that in a pop-up dialogue of sorts to output the streamers that are live. Is there a way to do this without making a text file and saving whoever is live to it?

Thanks :D

for i in {1..5}
do
   Streamer=$(awk "NR==$i" $StreamersFile)
   Live=$(curl -i --header 'Accept: application/vnd.twitchtv.v3+json' --header "Client-ID: $TwitchAPI" "https://api.twitch.tv/kraken/streams/$Streamer" | grep -wo 'live') 
   if [ "$Live" == live ]; then \
      : $((LiveStreamers++))
   fi
done

Here's a rough idea of what I want.

for i in {1..$LiveStreamers}
do
  $Streamer$i
done

zenity --info --text=$Streamer1 $Streamer2 $Streamer3 $Streamer4 $Streamer5

But I want to put those streamers that are live into a single variable like a list.

  • Export to an environment variable. – simlev Aug 10 '17 at 20:33
  • It's not clear what you're looking for. What do you mean by "remembered"? If you want it to persist after the script process ends, tough, you need to write it to a file. If you just want it to stick around while the script is executing, you're already setting two variables in your script, why won't setting another variable work? Please edit your question to clarify what you want. – 8bittree Aug 10 '17 at 20:44
  • I want it to save to a variable like $StreamersThatAreLive without having to make a variable for every line that a streamer is live. I don't know how to explain it further. Edited main post, no idea if it helps further – Interknet Aug 10 '17 at 20:54
  • Array variable maybe? – Kamil Maciorowski Aug 10 '17 at 21:02
  • @Interknet Yeah, I think that looks better. – 8bittree Aug 10 '17 at 22:26
0

Thanks to @KamilMaciorowski for the answer to use arrays. Here's the completed script:

    for i in {1..6}
do
   Streamer=$(awk "NR==$i" $StreamersFile)
   Live=$(curl -i --header 'Accept: application/vnd.twitchtv.v3+json' --header "Client-ID: $TwitchAPI" "https://api.twitch.tv/kraken/streams/$Streamer" | grep -wo 'live') 
   if [ "$Live" == live ]; then \
       StreamersThatAreLive=("${StreamersThatAreLive[@]}" "• $Streamer\n");
       List=${StreamersThatAreLive[@]}
   fi
done
zenity --info --text="Live right now:\n $List" --title="Live Right Now" 2> /dev/null

I'd explain how array's work, but I'm a newb to them. Here's the documentation I used which is super helpful: http://www.thegeekstuff.com/2010/06/bash-array-tutorial

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.