Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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 
share|improve this question
    
Was tired and overworked, edited my question and added the snipped... –  Martin Sep 4 '12 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? –  daniel kullmann Sep 4 '12 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 '12 at 8:39
add comment

1 Answer

up vote 4 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.