Converting a .bat file to a .sh file
Hi, I am taking a GIS Programming class. I use a MAC but the class is written for windows. I am having a bit of trouble converting the .bat file to a .sh file to run in terminal. Any help is greatly appreciated!!
The .bat file that was provided to me. Code:
cd /d c:\data\PhiladelphiaBaseLayers Code:
#!/bin/bash -x |
I don't understand what this
Code:
PATH=$ogr2ogrPATH:"/Applications/QGIS.app/Contents/Resources/python/plugins/processing/algs/gdal/ogr2ogr.py"$ogr2ogrPath \ Don't you just want Code:
ogr2ogrPath=/Applications/QGIS.app/Contents/Resources/python/plugins/processing/algs/gdal/ogr2ogr.py And what's with all of the delimeters ("\") all over the place? |
Thanks, Ok, I will try it without the "\"
When I run it like you have typed above, I receive this error: clip.sh: line 4: ogr2ogrPath: command not found clip.sh: line 8: syntax error: unexpected end of file Sorry, I am very new to this! |
When I tried it like the code you gave me, I received this error.
clip.sh: line 4: ogr2ogrPath: command not found clip.sh: line 8: syntax error: unexpected end of file why am I getting an unexpected end of file on line 8? I don't have anything on line 8. I am assuming my whole code is wrong? |
For the first error, I'm guessing you have a space between ogr2ogrPath and the "="? There can't be any spaces around the "=" in bash variable assignment.
For the second error, you're missing a "; done" at the end of each for loop. If this is going in a script, there's no need or reason to put the entire for loop on one line, you should split it up for readability. Code:
for shpfile in *.shp; do Code:
for shpfile in *.shp; do As far as I can tell there's no reason to have two separate for loops either. Just loop over *.shp once and run both commands inside. |
My new code...I think I will leave two for loops for now. One is creating the clipped files, the other is projecting the clipped files and I'm not sure I know how to type it with both in one. Mind looking over this for me? Also, does the ";" go after (*.shp;) or somewhere else? And do I need ";" anywhere else. Thank you again for helping me! I ran this code and I was still getting an error of unexpected end of line. :/ I am wondering if maybe my Path is incorrect...this is so frustrating.
Code:
#!/bin/bash -x |
Why are you putting half of the command on the for loop declaration line and then splitting up the arguments onto separate lines with leading "/"s? Please look again at how I wrote the for loop.
Maybe this will help: http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html |
New and improved code?? :) Ok, this time I ran it but I received another error message.
clip.sh: line 7: -skipfailures: command not found clip.sh: line 9: /Applications/QGIS.app/Contents/Resources/python/plugins/processing/algs/gdal/ogr2ogr.py: Permission denied do you think my code is incorrect? or my path is incorrect? I'm really confused. The .bat file seems so simple, I didn't think I would have too much trouble converting it. Thanks for the link too! Code:
#!/bin/bash -x |
Line 7: You misspelled ogr2ogrPath
Line 9: ogr2ogr.py doesn't have execute permissions. You can use Code:
chmod +x /Applications/QGIS.app/Contents/Resources/python/plugins/processing/algs/gdal/ogr2ogr.py |
Ok, this is how I typed this line of code (I didn't change anything else).
Code:
ogr2ogrPath="chmod +x/Applications/QGIS.app/Contents/Resources/python/plugins/processing/algs/gdal/ogr2ogr.py" so I have typed my .sh file in a text editor and I am running it in terminal (on a Mac) does that make any difference? Like I said, I am very new to shell scripting. I worked on this for several days. I really appreciate you helping me. This is probably the most progress I have made. |
Do not edit the script, go back to what it was. ogr2ogrPath was perfect as-is.
As I said in my previous post, "That command only needs to be run once from outside of your script." So, open a terminal, and run the exact command I posted, don't add "ogr2ogrPath=" or anything else, just run it exactly as written, then try your script again. All you're doing is adding execute permissions to the ogr2ogr.py file so that the shell will run it as a program. This only needs to be done once, ever. Once the file has execute permissions, you can execute it from within your script or on the command line or however you want. If you run Code:
ls -l /Applications/QGIS.app/Contents/Resources/python/plugins/processing/algs/gdal/ogr2ogr.py Code:
-rw-rw-r-- Code:
-rwxrwxr-x |
THANK YOU SO MUCH!!!! It worked! I also learned several new commands! I really appreciate it! Is there anything I need to do on this forum to let everyone know how awesome you are?
|
Glad you got it working!
You can mark the thread as solved up top in the "Thread Tools" menu. Beyond that, just clicking "Yes" next to "Did you find this post helpful" for any posts you found helpful will work. |
Try online batch file to shell script converter
Hello Guys,
Try this [link removed] For converting you windows batch file to linux bash (shell) script. This is quite cool for simple batch files. |
Quote:
Your name is OTP, and you posted to a thread that had been closed for FOUR YEARS, to post a link to a site that (amazingly) has the initials OTP. Read the LQ Rules. |
All times are GMT -5. The time now is 06:29 PM. |