Linux。讓alias支援輸入參數



alias別名指令是無法支援參數的輸入,例如下列的設定是無效的,會產生錯誤:
alias rm='cd $1'

但是可以利用自訂函數的方式讓alias支援參數,範例程式如下,當使用者輸入cd /bin時,執行函數checkdir並帶入參數/bin:
alias cd='checkdir'
function checkdir() {
    ldir=`pwd`
    if [ $1 == ".." ] && [ $ldir == "/export/home/test" ]
        then
          echo "Limit command"
        else
          #builtin cd /export/home/test/$1
          /export/home/test/bin/ cd /export/home/test/$1
        fi
}

Windows 11安裝時跳過網路連線