将变量从 htaccess 传递到 bash 脚本

发布于 2024-09-26 23:20:14 字数 254 浏览 0 评论 0原文

我试图将 cookie 的值传递给 bash 脚本:

RewriteCond %{HTTP_COOKIE} mycookie=(.*) [NC]
RewriteRule .* script.sh?cookievar=%1

...但似乎无法找出如何读取 bash 脚本中的 GET 变量。 (我想我向谷歌询问了错误的查询,但找不到任何相关信息)。

这可能吗?如果可以,请问如何实现?

谢谢,大卫

I'm trying to pass the value of a cookie to a bash script:

RewriteCond %{HTTP_COOKIE} mycookie=(.*) [NC]
RewriteRule .* script.sh?cookievar=%1

... but can't seem to find out how to read the GET variable in the bash script. (I suppose I'm asking Google the wrong queries, but can't find any info on this).

Is this even possible, and if so, please how?

Thanks, David

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吃素的狼 2024-10-03 23:20:14

您必须查看 Bash 中的 QUERY_STRING 环境变量才能访问 GET 变量。在您的情况下,应将其设置为 cookievar=VALUE。要提取变量的值,请使用如下内容:

COOKIEVAR=$(echo ${QUERY_STRING} | sed -n -e 's/^.*cookievar=\([^&]*\).*$/\1/p' -e 's/%20/ /g')

祝你好运!

You have to look at QUERY_STRING environment variable in Bash in order to access GET variables. In your case it should be set to cookievar=VALUE. To extract a variable's value, use something like this:

COOKIEVAR=$(echo ${QUERY_STRING} | sed -n -e 's/^.*cookievar=\([^&]*\).*$/\1/p' -e 's/%20/ /g')

Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文