Sign up ×
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 )
  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

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

1 Answer 1

up vote 4 down vote accepted

Should be:

for i in *.tab
  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"

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

Your Answer


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.