for loop question
I have a directory ~/test in which several sub-directories are there.
The sub-directory name has spaces and I can not rename them because the name depends on several processes. The names are like Code:
a 1 Code:
#!/bin/bash Code:
a Please help |
Just change around the field seperator.
Script: Code:
#!/bin/bash Code:
drwxr-xr-x 2 root root 4096 May 6 11:11 a 11 |
Use globbing directly in your for loop, don't use an intermediate variable
Code:
for i in ~/test/*; do echo $i; done |
2 people like this
Quote:
Code:
for i in ~/test/*; do echo "$i"; done |
Thanks to all for your responses.
Thanks suicidaleggroll for this wonderful one line solution. Thanks szboardstretcher, it worked for me. I could do another task because of you. I had a list of databases which appeared when I ran ls -1, I wanted to take backup of each database but same problem was there. There were spaces in database's name. I was using mysqldump after 'do' statement but this IFS="\n" was giving little trouble, it was changing the line in the list when letter 'n' was appeared in database name so I used IFS=$'\n' and it worked for me. Thanks again !!! |
All times are GMT -5. The time now is 09:54 PM. |