我喜欢听Sky.fm,我使用curl查询媒体信息。
目前我使用的是:
curl -s curl http://127.0.0.1:8080/requests/status.json | grep now_playing
这将返回:
"now_playing":"Cody Simpson - On My Mind"
我希望你能够为我提供以下服务:
Cody Simpson - On My Mind
也许更好的做法是将艺术家和标题放入单独的变量中。
artist: Cody Simpson
title: On My mind
解决方案
#!/bin/bash
a=`curl -s http://127.0.0.1:8080/requests/status.json | grep -Po '(?<=now_playing":")[^"]+'`
artist=$(echo $a | awk -F' - ' '{print $1}')
title=$(echo $a | awk -F' - ' '{print $2}')
echo $artist
echo $title