如何$在第一个命令中编写Bash忽略的函数?我想要这个,因为有时当我从网上粘贴一个命令时,它包含一个$第一个字符.
$ ls应该做什么ls或$ grep 'foo'应该做什么grep 'foo'.
这不起作用,因为$它不是有效的函数名称.
function $ {
...
}
Run Code Online (Sandbox Code Playgroud)
创建一个名为$somewhere 的文件$PATH,例如~/bin:
cd ~/bin
cat <<'EOF' > \$
#!/bin/sh
"$@"
EOF
Run Code Online (Sandbox Code Playgroud)
使其可执行:
chmod 755 \$
Run Code Online (Sandbox Code Playgroud)
并享受疯狂:
$ ls -l
total 92
-rwxr-xr-x 1 thomas thomas 13 Jan 3 19:09 $
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ ls
total 92
-rwxr-xr-x 1 thomas thomas 13 Jan 3 19:09 $
Run Code Online (Sandbox Code Playgroud)