以下是我如何使用线条:
grep "random text" /
我想根据找到的文字卷曲。这就是我尝试过的:
grep "random text" / | curl http://example.com/test.php?text=[TEXT HERE]
我不明白怎么做是在卷曲时使用grep的结果。如何替换我的grep结果的[TEXT HERE]
,以便获取正确的URL?
答案 0 :(得分:3)
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
答案 1 :(得分:1)
grep 'random text' file | xargs -I {} curl 'http://example.com/test.php?text={}'
答案 2 :(得分:0)
将grep
的输出放在变量中,并将该变量放在[TEXT HERE]
output=$(grep "random text" filename)
curl "http://example.com/test.php?text=$output"
引号很重要,因为?
对shell有特殊含义,而$output
可能包含原本会被处理的空格或通配符。
如果$output
可以包含特殊的网址字符,则需要对其进行网址编码。有关执行此操作的各种方法,请参阅How to urlencode data for curl command?。