ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I need this script to loop through a folder of images on my desktop on windows and change the pixels and format from .sid to .tif using Gdal.It wont run can use please help. I have cygwin on my pc but this is my first time using this program.
I'm afraid I don't know about cygwin, but I just tried your script and it runs fine. Just a suggestion, you don't need ls to list files in the for loop, bash does filename expansion:
Code:
for f in *.sid; do
Oh, another thing. If your filenames contain spaces, quote the variables:
Thanks. So now I can stop wasting my time in Python. I guess the real problem is that I am new to programming. Do you have any suggestions on how I can run the script instead of using Cygwin.
Why use ls, why not just "*.sid"? Using ls just makes things more complicated and breaks support for filenames with spaces.
Also, avoid backticks, usr $(command) instead. It's easy to nest and can't be confused with single quotes.
Finally, there's no need to use expr. bash can do arithmetic:
Code:
x=$(( x + 1 ))
Quote:
Originally Posted by tate89
# echo number of file we are on + name of file echo $x $f
# perform analysis, output to new file gdal_translate -of GTiff -outsize 31238 39915 $f res_$f
Did you intentionally comment out the commands? Why did you write text in front of them?
Quote:
Originally Posted by tate89
When I try in python idle in says invalid syntax. And im totally lost with cygwin.
What makes you think you can run a bash script with Python? That makes about as much sence as trying to compile a Python program with a C compiler. Run it like this:
Again, you don't need ls. It just makes the script more complex and makes it fail when there are spaces in filenames. Just replace it with this:
Code:
for f in *.sid; do
Quote:
Originally Posted by tate89
x='expr $x+1'
You're not running the command here, you're just setting the varaible x to the string "expr $x+1". Also, you need to separate the "$x", "+", and "1" parts into separate arguments. Use this instead:
Code:
x=$(expr $x + 1)
Or even better, use bash's built-in arithmetic. It's better because it doesn't need to launch another process:
I see you marked the above post as helpful. Did it fix your problem?
Anyway, what is does is convert Windows newlines (CRLF) to Unix newlines (LF) by removing all the CR characters from the file. When you write scripts, it's probably a good idea to either use a Unix editor or a Windows editor that lets you set it to use Unix newlines.
Yes it did. Thanks again. Now I am trying to figure out how to get Cygwin to read the gdal command gdal_translate.
Also today I learned to use dos2unix and I downloaded Vim to convert.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.