2番目のエイリアス内でエイリアスを拡張する

2番目のエイリアス内でエイリアスを拡張する

次のことができます。

alias tm=cd /opt/tomcat
alias tmbin=tm/bin

$ tmbin
$pwd
   /opt/tomcat/bin

??

私は私ができることを知っています:

alias tmbin=tm;cd bin

ベストアンサー1

シンプルな機能を使うのはどうですか?

# may contain bashisms
function tm () { cd "/opt/tomcat/$1"; }
alias tmbin='tm bin' # if that really is necessary

またはもう少し複雑なもの:

# more configurable
function tm () {
    cd /opt/tomcat
    case "$1" in
        "foo")
            # do something funky
            ;;
        "bar")
            # do something more funky
            ;;
    esac
}

おすすめ記事