2016-04-29 70 views
0

我已經使用命令alias filecreate='touch $1'在我的腳本中創建一個新的文件在我目前的工作目錄中,作爲自定義命令filecreate的幫助。但是當我執行腳本時,它顯示錯誤。另外我該如何讓命令接受2個參數中的一個文件名和其他路徑名。自定義命令的創建

+3

什麼腳本?什麼錯誤? – kaylum

+0

別名不能接受參數。如果需要處理參數,請使用函數。 – fedorqui

+0

相同:http://stackoverflow.com/q/36859162/1098603 – Matthieu

回答

3

alias filecreate=touch

或者其功能相當於:

filecreate(){ touch "[email protected]"; } 

將接受的參數任意數量並傳遞給touch

位置參數擴展通常不屬於別名,因爲別名與函數不同,不會獲得自己的位置參數數組。 別名是簡單的文本擴展。

alias filecreate='touch "$1"' 

時運行,像這樣:

filecreate SomeFile 

只會擴大到

filecreate "$1" SomeFile #$1 comes from the caller 

這不同於函數和腳本,這也得到自己的參數數組。

+0

[原始問題](http://stackoverflow.com/q/36859162/1098603);)另外,我認爲你的意思是擴展到「觸摸」 $ 1「SomeFile」 – Matthieu

+0

謝謝大家,非常感謝您的幫助。 @PSkocik我用filecreate創建了這個函數。 –