跨多個環境動態取得 Bash 和設定文件

跨多個環境動態取得 Bash 和設定文件

我想提出一種方法,無論使用者的檔案結構如何,都可以在互動式登入或非互動式登入時始終取得使用者的設定檔和 bash 設定檔。如果機器上安裝的是哪個版本的 Linux 也沒關係。

例如,並非每個人都有 ~/.bashrc 或 ~/.bash_profile 文件,但如果有,則應該獲取它們。

我最初的想法是這樣的(這是在 ssh 之後以編程方式運行):

[ -r /etc/profile ] && . /etc/profile;[ -r ~/.bash_profile ] && . ~/.bash_profile;[ -r ~/.profile ] && . ~/.profile;[ -r ~/.bashrc ] && . ~/.bashrc; OTHER COMMANDS...

然而,這並不完全按照我的計劃進行。 .bashrc 檔案中的函數似乎沒有載入。

我很感激任何幫助!謝謝。

編輯:新增完整的 SSH 命令

ssh -p 22 dev@123 '[ -r /etc/profile ] && source /etc/profile;[ -r ~/.bash_profile ] && source ~/.bash_profile;[ -r ~/.profile ] && source ~/.profile;[ -r ~/.bashrc ] && source ~/.bashrc;cd ~/apps/my-project/;npm install;bower install;grunt production;~/start-apps.sh;' In my case, the command 'grunt' isn't being found because it's initiated in the .bashrc file.

相關內容