linux 别名中执行别名

dwbf0jvd  于 2023-06-21  发布在  Linux
关注(0)|答案(1)|浏览(118)

我有以下别名,我希望第二个别名执行第一个别名。第二个别名没有检测到$单元。我怎么才能让它工作?

alias unit "`set unit = grep top def.tcl | tail -1 | item 2`"
alias ipcd 'unit ; cd flow/$unit/ip/'
nimxete2

nimxete21#

您正在执行命令替换set。在命令替换块内设置的变量在展开后被丢弃。您需要的是命令替代grep top def.tcl | tail -1 | item 2

alias unit "set unit = "\""`grep top def.tcl | tail -1 | item 2`"\"""
alias ipcd 'unit ; cd flow/$unit/ip/'

如果你想让它成为一个函数,请在.cshrc.tcshrc中设置以下内容:

alias function 'set argv = ( \!* ) ; source ~/.cshfuncs'

然后将函数添加到.cshfuncs

# Functions for C Shell.

set ret = -1
onintr exit

switch ("$1")
  case "ipcd":
    set unit = "`grep top def.tcl | tail -1 | item 2`"
    cd "flow/$unit/ip/"
    set ret = 0
    breaksw
  case "myfunc":
    echo "A function."
    set ret = 0
    breaksw
  default:
    echo "Function $1 not set."
endsw

exit:
set argv
exit $ret

相关问题