这是我如何利用线条:
grep "random text" /
我想根据找到的文字卷曲。这就是我尝试过的:
grep "random text" / | curl http://example.com/test.php?text=[TEXT HERE]
我不明白怎么做是在卷曲时使用grep的结果。我如何更换我的grep结果的[TEXT HERE]
,以便获得正确的URL?
curl --data-urlencode "text=$(grep PATTERN file)" "http://example.com/test.php"
将while
循环与read
结合使用:
grep PATTERN file | while read -r value ; do
curl --data-urlencode "text=${value}" "http://example.com/test.php"
done
grep 'random text' file | xargs -I {} curl 'http://example.com/test.php?text={}'
将grep
的输出放在变量中,并将该变量放在[TEXT HERE]
的位置
output=$(grep "random text" filename)
curl "http://example.com/test.php?text=$output"
引号很重要,因为?
对shell有特殊含义,而$output
可能包含空格或通配符,否则将被处理。
如果$output
可以包含特殊的URL字符,则需要对其进行URL编码。请参阅How to urlencode data for curl command?了解各种方法。