使用 grep 从详细调用中删除并保存在 shell 脚本函数中
我有一个curl put请求,我可以使用一些unix命令来查看stdout和stderr。
如果我添加行 2>&1 | grep -v "Authorization"
在我的curl请求结束时,我可以在CLI中看到我的curl的详细
输出,减去以“Authorization”开头的行
我尝试创建一个使用上述命令运行函数,但是当我在curl请求末尾调用该函数时(如下所示),它不再删除“授权”行。
function remove_item_from_verbose {
2>&1 | grep -v "Authorization"
}
echo -e "\n +++ Creating '$TENANT' tenant:\n"
# Create tenant
curl -L -X PUT "http://localhost:$HOST_PORT/admin/v2/tenants/$TENANT" \
--verbose \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $AUTHORIZATION" \
--data-raw "{\"allowedClusters\": [\"$CLUSTER\"]}" remove_item_from_verbose
I have a curl put request that I can use some unix command to see the stdout
and stderr
from.
If I add the line 2>&1 | grep -v "Authorization"
At the end of my curl request, I can see the verbose
output from my curl in my CLI minus a line that starts with "Authorization"
I tried creating a function with the above command, but when I call that function at the end of my curl request (like below) it no longer removes the "Authorization" line.
function remove_item_from_verbose {
2>&1 | grep -v "Authorization"
}
echo -e "\n +++ Creating '$TENANT' tenant:\n"
# Create tenant
curl -L -X PUT "http://localhost:$HOST_PORT/admin/v2/tenants/$TENANT" \
--verbose \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $AUTHORIZATION" \
--data-raw "{\"allowedClusters\": [\"$CLUSTER\"]}" remove_item_from_verbose
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,函数确实是这样工作的。您正在尝试为您的命令添加额外的详细信息。您可以这样做:
像这样,
$remove_item_from_verbose
成为命令的后缀。注意在
curl
前面添加了eval
,要求将此后缀视为命令的一部分。AFAIK functions do work like that. What you are trying to so is add extra details to your command. You can do it like that:
Like this,
$remove_item_from_verbose
becomes a suffix of your command.Note the addition of
eval
in front ofcurl
, it is required to have this suffix treated as part of the command.