簡體   English   中英

在shell腳本中使用變量時找不到ssh

[英]ssh not found when using variable in shell script

編寫Shell腳本時遇到奇怪的錯誤。

以下工作完全正常...

#!/bin/sh
if ssh root@example.com "[ -d /web ]"; then 
    echo "That directory exists!";
fi

並運行沒有錯誤。 一旦我嘗試使用變量...

#!/bin/sh
USER="root"
LOC="example.com"
PATH="/web"

if ssh $USER@$LOC "[ -d $PATH ]"; then 
    echo "That directory exists!";
fi

它只是返回...

6: test.sh: ssh: not found

即使只是將變量設置在頂部並留下底部硬編碼,也會引發此錯誤。

$PATH被本地shell用於查找二進制文件,在本例中為ssh 一旦將其設置為/web ,shell就會嘗試找到不存在的/web/ssh

使用其他變量名稱:

remote_path="/web"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM