![](/img/trans.png)
[英]What's the best way to mix remote expect scripts and local bash commands?
[英]LOCAL_DIR variable prepends the scripts current directory (totally not what I expect)
考慮下面的簡單rsync腳本,我是tryint拍的:
#!/bin/bash
PROJECT="$1"
USER=stef
LOCAL_DIR="~/drupal-files/"
REMOTE_HOST="hostname.com"
REMOTE_PROJECTS_PATH=""
# Should not have anything to change below
PROJECT_LIST="proj1 proj2 proj3 quit"
echo "/nSelect project you wish to rsync\n\n"
select PROJECT in $PROJECT_LIST
do
if [ "$PROJECT" = "quit" ]; then
echo
echo "Quitting $0"
echo
exit
fi
echo "Rsynching $PROJECT from $REMOTE_HOST into" $LOCAL_DIR$PROJECT
rsync -avzrvP $USER@$REMOTE_HOST:/var/projects/$PROJECT/ $LOCAL_DIR$PROJECT
done
echo "Rsync complete."
exit;
在rsync命令中設置的變量$LOCALDIR$PROJECT
始終包含腳本路徑:
輸出 :
Rsynching casa from hostname.com.com into ~/drupal-files/casa
opening connection using: ssh -l stef hostname.com rsync --server --sender -vvlogDtprz e.iLsf . /var/groupe_tva/casa/
receiving incremental file list
rsync: mkdir "/home/stef/bin/~/drupal-files/proj1" failed: No such file or directory (2)
rsync error: error in file IO (code 11) at main.c(605) [Receiver=3.0.9]
帶mkdir
的行不應包含/ home / stef / bin,為什么bash在變量上添加了腳本的運行目錄?
謝謝
LOCAL_DIR="~/drupal-files/"
該字符串用引號引起來,因此擴展了路徑名,並且變量將包含文字字符串。
刪除引號。
$ x="~/test"; echo $x
~/test
$ x=~/test; echo $x
/home/user/test
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.