在 csh 中转义 $

Pab*_*mer 2 shell csh

我怎样才能$在csh中逃脱?在<双引号> ( "") 内。我正在尝试这样做,但无法逃避 <dollar> 符号 ( $)

alias e "echo \\!:2-$"
Run Code Online (Sandbox Code Playgroud)

这可行,但不足以满足我的需求

alias e echo \\!:2-$
Run Code Online (Sandbox Code Playgroud)

Sti*_*lez 5

这个老问题的建议答案不正确。

在 CSH 和其他 shell 中,无论引号的类型如何,都可以完成此操作,但对于某些 shell,如果使用双引号,则需要先退出双引号。

以下内容应该适用于(几乎)所有 shell,因此为了简单起见,我使用它。我使用反引号来获取命令的输出,因为它更易于遵循并且避免需要添加额外的“$”符号(更现代的风格)。请注意“$”的不同用法,即实际获取变量和作为文字(为了方便起见,在单引号内部和外部)。

这应该适用于大多数 shell。

命令示例:

echo "My terminal is $term, first file found in /dev is </dev/`ls /dev | head -n 1`>, the
dollar symbol is '"`echo '$'`"', and a newspaper costs "`echo '$'`"2.50."
Run Code Online (Sandbox Code Playgroud)

输出:

My terminal is xterm, first file found in /dev is </dev/acpi>, the dollar symbol
is '$', and a newspaper costs $2.50.
Run Code Online (Sandbox Code Playgroud)