[英]bash single quote escaping is driving me mad
我正在尝试使用gdalsrsinfo从.shp中获取proj4字符串,然后将其传递给ogr2ogr,以用于批处理重新投影循环。 它已经接近工作了,但是单引号已传递给ogr2ogr命令,我不知道如何去除它们:
我的剧本:
#!/bin/bash
for f in *.shp; do
projsrs=$(gdalsrsinfo -o proj4 $f)
ogr2ogr -f "ESRI Shapefile" -s_srs "$projsrs" -t_srs EPSG:3857 ${f%}3857.shp $f
done
gdalsrsinfo
运行gdalsrsinfo
命令将返回:
username:shpfrm username$ gdalsrsinfo -o proj4 filename.shp
'+proj=utm +zone=11 +datum=WGS84 +units=m +no_defs '
当我使用bash -x
测试输出时,我看到''\\'
在字符串的开头,而“ \\'''
在结尾。
+ for f in '*.shp'
++ gdalsrsinfo -o proj4 filename.shp
+ projsrs=''\''+proj=utm +zone=11 +datum=WGS84 +units=m +no_defs '\'''
+ ogr2ogr -f 'ESRI Shapefile' -s_srs ''\''+proj=utm +zone=11 +datum=WGS84 +units=m +no_defs '\''' -t_srs EPSG:3857 filename.shp3857.shp PC_Sec05_Frm64.shp
Failed to process SRS definition: '+proj=utm +zone=11 +datum=WGS84 +units=m +no_defs '
我需要的是:
ogr2ogr -f 'ESRI Shapefile' -s_srs '+proj=utm +zone=11 +datum=WGS84 +units=m +no_defs ' -t_srs EPSG:3857 filename.shp3857.shp filename.shp
您尚未显示命令的输出,但是如果确实有不需要的引号,则可以将其删除。 参考: http : //wiki.bash-hackers.org/syntax/pe#search_and_replace
#!/bin/bash
for f in *.shp; do
projsrs=$(gdalsrsinfo -o proj4 "$f")
ogr2ogr -f "ESRI Shapefile" -s_srs "${projsrs//\'/}" -t_srs "EPSG:3857" "${f}3857.shp" "$f"
done
另外,您应始终引用文件名,因为它们可以包含空格。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.