3

This is a script which looks for .tab files in a folder an should imports them with ogr2ogr, but I fail with the correct bracing.

for i in $( ls *.tab )
do
  echo item: $i

  ogr2ogr -f PostgreSQL -s_srs EPSG:21781 -t_srs EPSG:4326 -overwrite \
          -nln $TBL_NAME PG:'"host=localhost user='$DBUSER' dbname='$DBNAME'"' $i
done

And I need a command line to execute the ogr2ogr section in this way:

ogr2ogr -f "PostgreSQL" -s_srs "EPSG:21781" -t_srs "EPSG:4326" -overwrite \
        -nln "geom_tour" PG:"host=localhost user=postgres dbname=gis" DMC_34093.tab 
3
  • Was tired and overworked, edited my question and added the snipped...
    – Martin
    Sep 4, 2012 at 8:17
  • 1
    You forgot the host=localhost part in your code. Also why don't you just do for i in *.tab? And what is that code assigning to variable j for? Sep 4, 2012 at 8:30
  • Thx for the comment. j was from something else, removed it now added the host=localhost (which isn't necessary) - still not working... Problem is in the braces :(
    – Martin
    Sep 4, 2012 at 8:39

1 Answer 1

4

Should be:

for i in *.tab
do
  echo item: $i

  ogr2ogr -f "PostgreSQL" -s_srs "EPSG:21781" -t_srs "EPSG:4326" -overwrite -nln "$TBL_NAME" PG:"host=localhost user=\'${DBUSER}\' dbname=\'${DBNAME}\'" "$i"
done

You need to use double quotes to let the shell expand variables like ${DBUSER} inside.

Note for i in *.tab instead of for i in $(ls *.tab). Don't parse the output of ls, all it does is mangle file names with spaces and other special characters.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .