2017-06-01 100 views
0

我在shell中編寫了一個代碼來檢索當前日期類型爲「OLO2OLO_20170601_FATTURA.txt.zip」的文件。 下面是我的代碼:通過shell腳本檢查ftp服務器中的文件

#!/bin/ksh 

DATE=`date '+%Y%m%d'` 
FILE="OLO2OLO_$DATE_FATTURA.txt.zip" 

/usr/bin/ftp -n 93.179.136.9 << !EOF! 
user abc 1234 
cd "/0009/Codici Migrazione" 
get $FILE 
bye 
!EOF! 

但我發現了以下錯誤:

$ ./ftp_test1 
Failed to open file. 

回答

1

你必須把變量名大括號。

FILE="OLO2OLO_${DATE}_FATTURA.txt.zip" 

下劃線在變量名中有效。這不是一個令牌分隔符。

正式

name is a word consisting only of alphanumeric characters and underscores, and beginning with an alphabetic character or an underscore.

目前殼試圖替代的值與名DATE_FATTURA一個變量,它是空的,所以你FILE變量變成OLO2OLO_.txt.zip這樣的文件可能不會在遠程服務器上。

+0

是的,非常感謝:-) 它的工作。 – User123

相關問題