2017-04-25 76 views
0

我在Linux操作系統Ubuntu以下bash腳本將打開一個新的終端具有多個突出部和在每個標籤它執行ssh命令來訪問遠程路由器:執行別名命令

#!/bin/bash 

gnome-terminal --tab -e "ssh [email protected]" --tab -e "ssh [email protected]" 

在在.bashrc文件,我已經包括以下別名命令的定義:

alias router4='ssh [email protected]' 
alias router5='ssh [email protected]' 

當我與這些別名命令的第一個腳本代替全ssh命令,每個選項卡給了我以下錯誤:

There was an error creating the child process for this terminal

Failed to execute child process "router6" (No such file or directory)

如何解決這個問題?

注意:當我在maually打開的選項卡中執行以前的別名命令,他們完美的工作。

回答

1

你可以嘗試從一個別名在.bashrc切換的功能。根據bash的文檔,在大多數情況下,函數比別名要好。在你的情況下,因爲你沒有將bash作爲登錄環境運行,所以它可能會更好。添加到您的.bashrc並註釋掉別名:

router4() { 
    /usr/bin/ssh [email protected] 
} 

如果沒有對自己的工作,你可以嘗試定義router4後您的.bashrc加入export -f router4

0

您需要通過bash執行它:

gnome-terminal --tab -e "bash -c router4" 
+0

終端啓動,但它報告'bash:router4:command not found'。我還添加了'shopt -s expand_aliases',但沒有任何改變。 – IoT

+0

好吧,是的,你沒有在你的問題中指定;保持窗口打開檢查這些解決方案:http://stackoverflow.com/a/3512861/5348860 – odradek

+0

我解決了保持終端打開的問題,它通過更改配置文件名稱完成。現在我有另一個問題,請檢查我以前的答案。 – IoT