-2
jsonval() {
temp=`echo $haystack | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" ' {n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed ' s/\"//g' | grep -w $needle`
echo ${temp##*|}
}
dev_key='xxxxxxxxxxxx'
zip_code='48446'
city='Lapeer'
state='MI'
red=$(tput setaf 1)
textreset=$(tput sgr0)
haystack=$(curl -Ls -X GET http://api.wunderground.com/api/$dev_key/conditions/q/$state/$city.json)
needle='temperature_string'
temperature=$(jsonval $needle $haystack)
needle='weather'
current_condition=$(jsonval $needle $haystack)
echo -e '\n' $red $current_condition 'and' $temperature $textreset '\n'
此代码应该使用开发人员密钥来解析json天气数据到终端以调用信息。有人可以解释这段代码在做什么吗? sed在做什么特殊字符?
这是完整的代码,有人可以解释sed在做什么,我知道它应该作为一种替代方法,但为什么会出现如此多的斜杠和特殊字符?
什么是echo $ {temp ## * |}在做什么,所有这些特殊字符都让我很难理解这段代码。
运行这种CMD的用你自己的输入并看到...... echo“a \\ b”| sed's/\\\\\ // \ // g' http://www.grymoire.com/Unix/Sed.html#uh-1 – 2014-12-07 04:28:27
其次,它的风格并不好,写得一团糟,从中学习会引导你错误的方式。 – BMW 2014-12-07 04:34:04
“$干草堆”的价值是什么?如果没有这个值,就不可能知道sed对字符串做了什么,你将不得不将代码切成片段,尝试每个片断查看它们的输出。 – repzero 2014-12-07 04:53:40