如何使用perl命令从URL读取查询参数值

gla*_*666 5 url bash perl

在shell中,我需要从URI中提取特定的查询参数.

我试图用这个来获得"抵消"价值

echo "/mypath/index.php?offset=20&query=uro" | perl -MURI -le 'chomp($url = <>); print URI->new($url)->query_form("offset")'
Run Code Online (Sandbox Code Playgroud)

但它总是会回归 offset=20&query=uro

请帮忙

Tot*_*oto 4

query_form返回一个哈希值,将脚本更改为:

perl -MURI -le 'chomp($url = <>); print +{URI->new($url)->query_form}->{offset}'
Run Code Online (Sandbox Code Playgroud)

为了处理多行:

perl -MURI -nle 'print +{URI->new($_)->query_form}->{offset}'
Run Code Online (Sandbox Code Playgroud)