bash 中函数的多个名称/别名
Multiple names / aliases for a function in bash
是否可以为同一个 bash 函数设置多个别名,而不必跨多个别名重新定义函数的内容?
您只需要为它定义别名,而不是在同一个函数体中声明多个函数:
# attach a bash shell to a running docker container
function dexb {
docker exec -it "" /bin/bash
}
# attach a sh shell to a running docker container
function dexs {
docker exec -it "" /sh
}
# Now instead of creating another function say 'dex' with the same
# content as the function 'dexb'
# I'll just create an alias
alias 'dex'='dexb'
是否可以为同一个 bash 函数设置多个别名,而不必跨多个别名重新定义函数的内容?
您只需要为它定义别名,而不是在同一个函数体中声明多个函数:
# attach a bash shell to a running docker container
function dexb {
docker exec -it "" /bin/bash
}
# attach a sh shell to a running docker container
function dexs {
docker exec -it "" /sh
}
# Now instead of creating another function say 'dex' with the same
# content as the function 'dexb'
# I'll just create an alias
alias 'dex'='dexb'