[英]BASH: grep doesn't work in shell script but echo shows correct command and it works on command line
[英]Command doesn't work in script, but works in shell
我正在編寫一個使用SSH“配置文件”的腳本 , 〜/ scripts / ssh-profiled.sh
PROFILE=`cat ~/script/ssh-profiles/$1`
echo [ssh $PROFILE]
ssh $PROFILE
〜/腳本/ SSH型材/ tummi
-i ~/Dropbox/security/key-nopass/key-nopass.pvt bart@example.com
當我運行腳本時,它失敗了:
bart@bart-laptop:~$ script/ssh-profiled.sh tummi
[ssh -i ~/Dropbox/security/key-nopass/key-nopass.pvt bart@example.com]
Warning: Identity file ~/Dropbox/security/key-nopass/key-nopass.pvt not accessible: No such file or directory.
bart@example.com's password:
但這有效:
bart@bart-laptop:~$ ssh -i ~/Dropbox/security/key-nopass/key-nopass.pvt bart@example.com
Linux tummi 2.6.32-24-server #39-Ubuntu SMP Wed Jul 28 06:21:40 UTC 2010 x86_64 GNU/Linux
Ubuntu 10.04.1 LTS
Welcome to the Ubuntu Server!
我的腳本中是否有錯誤/陷阱?
您文件中的〜需要是完整的主目錄路徑,它不會被擴展。
我的猜測是,當以這種方式傳遞時,“〜/”沒有被解釋為預期。 嘗試使用顯式完整路徑。
.pvt文件的權限是什么? 如果只有您具有讀訪問權限,並且沒有人可以執行它,那么您的腳本可能甚至無法查看該文件。 這可能就是為什么你得到"...not accessible: No such file or directory."
信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.