从 python 行命令中转义 @

发布于 2024-08-19 11:35:23 字数 214 浏览 4 评论 0原文

我不知道这是 python 还是 shell(linux 上的 zsh)的问题,我有一个这样的参数:“@xyz”以“@”开头

python the_script.py first_argument @second_argumentthird_arg

I尝试用 \ 或 \\ 转义 @,或使用“”,但程序无法启动。如果我离开@second_arguments 中的@,一切都会好的。

I don't know if this is a problem with python or with the shell (zsh on linux), I've an argument like this: "@xyz" that starts with a "@"

python the_script.py first_argument @second_argument third_arg

I tried to escape @ with \ or \\, or use "" but the program doesn't start. If I leave the @ from @second_arguments everything's ok.

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

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

发布评论

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

评论(1

赏烟花じ飞满天 2024-08-26 11:35:23
  1. 也许“@”是 zsh 中的全局字符,扩展到当前目录中的所有符号链接。尝试用“@@”转义它?

  2. 尝试使用echo运行参数列表,即:

    echo the_script.pyfirst_argument@second_argumentthird_arg

这样,你就可以判断它是否是扩展或按原样传递给脚本。

  1. Perhaps the "@" is a glob character in zsh, expanding to all symbolic links in the current directory. Try escaping it with "@@"?

  2. Try running the argument list with echo, i.e:

    echo the_script.py first_argument @second_argument third_arg

That way, you can figure out if it was expanded or passed as-is to the script.

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