如何编写 Bash$在第一个命令中忽略的函数?我想要这个,因为有时当我从 web 粘贴命令时,它包含一个$in 第一个字符。
$ ls应该做ls或$ grep 'foo'应该做grep 'foo'。
这将不起作用,因为$它不是有效的函数名。
function $ {
...
}
$在您的某处创建一个名为的文件$PATH,例如~/bin:
cd ~/bin
cat <<'EOF' > \$
#!/bin/sh
"$@"
EOF
使其可执行:
chmod 755 \$
并享受疯狂:
$ 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 $