bash script - for loop question
This is actually my first attempt at anything useful with a bash script. This is a modified version of two functions shown in Learning the bash Shell book (oreilly). What is should do is recursively rename all the files in a directory structure given at the command prompt. I know it could probably be many times better, but it's really mostly an exercise so I can learn. Before I go on, here is the script. Keep in mind I'm trying to use purely bash and nothing else here, again for learning purposes.
Code:
#!/bin/bash Quote:
Any constructive comments welcome and thanks. Brian |
The problem (basically) is, when you split the parameters (for x in "$@"), they are split by spaces, and the splitting doesn't take quotes into account. If you do this at the top of your script:
Code:
IFS=`echo -e "\012\015"` If you're interested in alternatives, this is how I would do the whole script: Code:
#!/bin/bash |
Thank you so much!
That was the perfect solution. I sort of thought IFS would be involved somehow but I didn't even think of using ls -1 in that way. So, basically, "$@" will always, with a normal IFS variable interpret seperate arguments as divided by space if I understand you correctly? Thanks again, Brian |
That's right. The default IFS contains tab, newline and space, so it will split by all of these, and treat quotes as part of the 'word' they are attached to. Annoying, huh? I've been bitten by that before, expecting quotes to separate arguments... took me quite a while to figure out what was going on :)
|
All times are GMT -5. The time now is 02:31 PM. |