linux – 在bash别名或函数中使用历史扩展
发布时间:2020-12-14 00:32:42 所属栏目:Linux 来源:网络整理
导读:我想做一件简单的事情让我的队友生活更轻松.他们不断地将报价复制到命令行中,这些命令行的格式化会破坏命令,即:“test”与“test” 事实证明,令人惊讶的是: function damn() { !!:gs/“/" } 要么: alias damn='!!:gs/“/"' 似乎都没有工作,并一直给我错误
我想做一件简单的事情让我的队友生活更轻松.他们不断地将报价复制到命令行中,这些命令行的格式化会破坏命令,即:“test”与“test”
事实证明,令人惊讶的是: function damn() { !!:gs/“/" } 要么: alias damn='!!:gs/“/"' 似乎都没有工作,并一直给我错误 -bash: !!:gs/“/" : No such file or directory 要不就:
我必须在这里遗漏一些明显的东西. 解决方法
!在函数或别名中不起作用.根据bash手册:
您可以使用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. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |