我想做一件简单的事情让我的队友生活更轻松.他们不断地将报价复制到命令行中,这些命令行的格式化会破坏命令,即:“test”与“test”
事实证明,令人惊讶的是:
function damn() { !!:gs/“/" }
要么:
alias damn='!!:gs/“/"'
似乎都没有工作,并一直给我错误
-bash: !!:gs/“/" : No such file or directory
要不就:
>
我必须在这里遗漏一些明显的东西.
解决方法:
!在函数或别名中不起作用.根据bash手册:
History expansion is performed immediately after a complete line is read, before the shell breaks it into words.
您可以使用builtin fc命令:
[STEP 100] # echo $BASH_VERSION
4.4.19(1)-release
[STEP 101] # alias damn='fc -s “=\" ”=\" '
[STEP 102] # echo “test”
“test”
[STEP 103] # damn
echo "test"
test
[STEP 104] #
为了快速引用,以下是help fc的输出.
fc: fc [-e ename] [-lnr] [first] [last] or fc -s [OLD=NEW] [command]
Display or execute commands from the history list.
fc is used to list or edit and re-execute commands from the history list.
FIRST and LAST can be numbers specifying the range, or FIRST can be a
string, which means the most recent command beginning with that
string.
Options:
-e ENAME select which editor to use. Default is FCEDIT, then EDITOR,
then vi
-l list lines instead of editing
-n omit line numbers when listing
-r reverse the order of the lines (newest listed first)
| With the `fc -s [OLD=NEW ...] [command]' format, COMMAND is
| re-executed after the substitution OLD=NEW is performed.
A useful alias to use with this is r='fc -s', so that typing `r cc'
runs the last command beginning with `cc' and typing `r' re-executes
the last command.
Exit Status:
Returns success or status of executed command; non-zero if an error occurs.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。