2017-09-29 2 views
0

シェルでこれをテストするたびに表示されますが、スクリプトから実行しているときには表示されません。curl urlに変数を挿入できません

シェル:

fips=55555 
echo https://www2.census.gov/geo/tiger/TIGER2016/ROADS/tl_2016_$fips'_'roads.zip 
>>https://www2.census.gov/geo/tiger/TIGER2016/ROADS/tl_2016_55555_roads.zip 

私はこのようなテキストファイル内のいくつかのデータをループにしようとしている:

enter image description here

カールURLにそれ/入力をパース:

出力には、このように上書きされた文字列の先頭があります。

./readFipsData.txt 
>>_roads.zipw2.census.gov/geo/tiger/TIGER2016/ROADS/tl_2016_48001 

注:Git Bash for Windowsは違いがあれば使用しています。

cat ./testFipsData.txt | 
while read line 
do 
    counter=0 
    for col in $line 
    do 
    if [ $counter == 0 ] 
    then 
     state=$col 
    elif [ $counter == 1 ] 
    then 
     county=$col 
    elif [ $counter == 2 ] 
    then 
     fips=$col 
    fi 
     ((counter++)) 
    done 
#curl -k -o ./$county.zip "https://www2.census.gov/geo/tiger/TIGER2016/ROADS/tl_2016_$fips_roads.zip" 
echo https://www2.census.gov/geo/tiger/TIGER2016/ROADS/tl_2016_$fips'_'roads.zip 
done 
+1

を入力ファイルは、おそらくMSWinの行末が含まれています。入力から '$ '\ r"を取り除いてください。 – choroba

+2

パイプを使用せず、入力リダイレクトを使用する 'done Barmar

+0

@chorobaいいえ、問題は彼がパイプのためにサブシェルに変数を設定していることです。 – Barmar

答えて

0

ご提案のすべてのおかげで、ここで働いていたものです:

cat ./testFipsData.txt | 
while read state county fips 
do 
fips=${fips%$'\r'} 
curl -k -o ./$county.zip https://www2.census.gov/geo/tiger/TIGER2016/ROADS/tl_2016_$fips'_'roads.zip 
done 
関連する問題