1

I've been trying to make a script and in this script I would like to update the folder name and a bunch of other things using a variable.

the folder i create is going to be called the latest version release name it has on github.

#!/bin/sh
content=$(curl -s -L https://github.com/FAForever/client/releases)
fl=tr '\n' ' ' < $content | grep -E "^<div class=\"release-title\">.*</div>$"
echo $fl



#!/bin/sh
s=$(curl -s https://github.com/FAForever/client/releases | grep "div class='release-title'")
echo "$s"

I've looked all over the web for this and noone does this specific setup (source curl/ output shell var)

all have some sort of file input or output or other and I can't make use of their solutions.

what is the correct syntax in shell to grab only one class' content and store it in a shell variable?

Thank you.

1

the github API https://api.github.com/ returns json which is can be nicely crunched with the command line tool jq

What do you need ? a list of releases ? ... try this

curl https://api.github.com/repos/FAForever/client/releases | jq .[].tag_name

which gives you output

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  107k  100  107k    0     0   314k      0 --:--:-- --:--:-- --:--:--  314k
"0.12.0-pre2"
"0.12.0-pre1"
"0.11.60-p1"
"0.11.61-pre2"
"0.11.61-pre"
"0.11.60"
"0.11.59-pre"
"0.11.58"
"0.11.57"
"0.11.55"
"0.11.54"
"0.11.53"
"0.11.52"
"0.11.51"
"0.11.50"
"0.11.49"
"0.11.47"
"0.11.16+291"
"0.11.14"
"0.11.8+270"
"0.11.7+267"
"0.11.3+247"
"0.11.0"
"0.10.125"
"0.10.124"
"0.10.123"
"0.10.124-pre"
"0.10.123-pre"
"0.11-pre-3"
"0.11-pre-2"

if you say "Just show me the latest" then issue

sudo apt-get install jq

curl --silent  https://api.github.com/repos/FAForever/client/releases | jq .[].tag_name|sort -n|tail -1

with output

"0.12.0-pre2"

now to bundle into a shell script vi show_latest.sh

#!/bin/bash

latest_release=$(curl --silent  https://api.github.com/repos/FAForever/client/releases | jq .[].tag_name|sort -n|tail -1)

echo latest_release $latest_release

which generates output

latest_release "0.12.0-pre2"
  • that's very good although i need it to be something that is preinstalled in ubuntu. right now i get "jq not installed" – tatsu Dec 21 '16 at 18:56
  • now it shows shell variable populated with answer – Scott Stensland Dec 21 '16 at 19:41
1

Same as Scott's answer but use Python instead.

curl https://api.github.com/repos/FAForever/client/releases | python -c 'import sys,json; print "\n".join(map(lambda x: x["tag_name"],json.load(sys.stdin)))'

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.