訪問功能的.bashrc我.bashrc
這樣創建的函數;如何在新的終端
#!/bin/bash
function test() { ls; }
export -f test
並且像這樣在新的終端中調用它;
$ test
結果是test: command not found
我做了什麼錯在.bashrc
訪問功能?
訪問功能的.bashrc我.bashrc
這樣創建的函數;如何在新的終端
#!/bin/bash
function test() { ls; }
export -f test
並且像這樣在新的終端中調用它;
$ test
結果是test: command not found
我做了什麼錯在.bashrc
訪問功能?
您可能希望做一個「功能」的文件在你的home目錄和源在你的.bashrc。
前:如下所示,這是行不通的。
%[email protected]> add 2 3
bash: add: command not found...
定義在$ HOME功能/。功能
%[email protected]> cat ~/.function
add()
{
echo "$1 + $2" | bc
}
這裏是我如何採購在我的$ HOME/.bashrc中
%[email protected]> cat ~/.bashrc|grep source|grep func
source $HOME/.function
%[email protected]>
所有功能您可能需要打開它或重新登錄,或者在提示符下鍵入bash,它應該可以工作。
現在,它的工作原理:
%[email protected]> add 2 3
5
%[email protected]>
請試試看。謝謝。
你在調用函數之前運行過'source .bashrc'嗎? – codeforester
很有趣,因爲'測試'存在於任何系統上。 – jm666
你在哪裏寫了'.bashrc'文件?而且,你是否正在運行'bash'? –