gpt4 book ai didi

bash - 忽略第一个命令中的 $

转载 作者:行者123 更新时间:2023-11-29 09:03:18 25 4
gpt4 key购买 nike

我如何编写 Bash 在第一个命令中忽略 $ 的函数?我想要这个,因为有时当我从网络粘贴命令时,它的第一个字符包含一个 $

$ 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 $

关于bash - 忽略第一个命令中的 $,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14145273/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com