[CentOS] bash script reading directory with while and do
Elias Persson
delreich at takeit.se
Wed May 28 12:10:39 UTC 2014
On 2014-05-25 12:08, Paolo De Michele wrote:> !/bin/bash
>
> while read line;
> do
> read NR PATH NAME<<<$(IFS=" "; echo $line)
>
> cd /var/www/clients/
> cp -R $PATH /backup/temp/www/
> cd /backup/temp/www/
>
> tar cfz `date +%F`_$NAME.tar.gz web$NR/
> mv *.tar.gz /backup/www/test/
> rm -rf /backup/temp/www/*
>
> done < sites.txt
A few things:
1. A shebang is two chars, "#!", not just an exclamation point.
(possibly just a typo / copy error)
2. $PATH is special, use something else (e.g. $path).
3. Your `tar` stanza is wrong (if it's not obvious to you why that is,
now is a good time to make a habit of using long options
(e.g. `--gzip`) whenever possible).
4. Always quote variables that could possibly have whitespace in them
($NAME in this case).
What is it you're trying to accomplish with the IFS and echo?
Why not just
while read nr path name;
do
: stuff goes here
done
More information about the CentOS
mailing list