csh 别名中的 \!^ 有何作用

Ket*_*Dog 2 ssh csh port-forwarding

注意:我的shell是csh

一位前同事给了我以下命令,将其放入我的.cshrc

alias bastion 'ssh -L \!^\:<some_ip_address> <username>@<something.com>'

请注意,<> 之间的内容是实际值。

现在,当我在 shell 上运行此命令时,出现以下错误:Bad ! arg selector.

我一直在网上搜索 的类似用法,ssh -L但没有找到使用\!^\在 前面使用 的语法的示例:

知道这个命令实际上想要做什么以及为什么它不起作用吗?

Pau*_*ski 5

我自己不是 csh 用户,但这似乎是历史控制。

\n
\n

!^给出前一个命令的第一个参数。这与 相同!:1。请记住,正如^(插入符号) 是正则表达式中的行首锚点 (26.4) 一样,!^给出了开始历史参数。

\n
% cat fn fn1 fn2\n ...\n% more !^\nmore fn\n
Run Code Online (Sandbox Code Playgroud)\n
\n

https://docstore.mik.ua/orelly/unix/upt/ch11_07.htm

\n

\\我假设)是转义,以防止!^过早被解释(即不是在定义别名时而是在使用别名时)。请参阅此处的示例

\n

所以这基本上实现了别名的参数处理。该别名旨在使用绑定到\xc2\xb9 的本地端口号进行调用。

\n
$ bastion 8080 \n# should be executed as\n$ ssh -L 8080:<some_ip_address> <username>@<something.com>\n\n$ bastion 8080 some argument\n# is probably (I\'m still no csh user) executed as\n$ ssh -L 8080:<some_ip_address> <username>@<something.com> some argument\n
Run Code Online (Sandbox Code Playgroud)\n

作为结论,我认为Bad ! arg selector.意味着没有参数可供选择,因为您尝试将其运行为bastion

\n
\n

\xc2\xb9我假设你的替换<some_ip_address>实际上是一个IP +端口?不然这个-L论点就有点奇怪了。

\n