2

How do I return a variable in GRASS GIS on a Windows machine?

For example I set a list of files to define my region. I already figured out that I can't use the bash command export, I need to use set instead. The command should be okay, but it doesn't return $MAPS.

set MAPS=`g.mlist type=rast sep=, pat="*"`  
g.region rast=$MAPS -p

I tried already to check if the variable is set (echo $MAPS), but without success.

2
  • 1
    Those back ticks are linux syntax to evaluate what's inside of them first. It won't work on windows to capture output in a variable. This is a frustrating problem I've faced a lot too. The best I've been able to find is something like FOR /F "delims=" %i IN ('echo "Hello World"') DO set output=%i then echo %output% gives "Hello World" from stackoverflow.com/questions/108439/…. But it's so cumbersome that at this point I usually switch to python. Hopefully you get a good answer because I'd like to see it too. – user55937 Sep 2 '15 at 13:11
  • 1
    Thx @user55937, I think I will give up and switch back to Linux... It's just too frustrating. – wittich Sep 3 '15 at 14:35
2

That's because $MAPS doesn't exist from windows command line.

You need to call variables with %MAPS% (surrounded by % sign).

But also consider that grass when installed either from the grass site using the stand alone installer or osgeo4w they both come with MSYS - a unix like shell. You can use that instead which lets you stay with bash like syntax.

2
  • It doesn't work, I tried a echo %MAPS% and it returns just the variable name. I'll try to use MSYS that sounds like a what I want... – wittich Sep 3 '15 at 7:20
  • It seams like cmd is not fully loaded. If I set set test=123 and let it return directly echo %test% it just print %test%. Normally it only does that in cmd when the variable is not set. By the way with MSYS I can't run grass64, it seem like something is wrong implemented. Maybe I should reinstall OSGeo4W or just switch into the virtual machine. – wittich Sep 3 '15 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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