[CentOS] how to do repetetive command in shell

Tony Schreiner tony.schreiner at bc.edu
Thu Oct 21 18:59:11 UTC 2010


On Oct 21, 2010, at 2:50 PM, Pintér Tibor wrote:

>
>> USER1="roland"
>> USER2="dany"
>> USER3="kevin"
>>
>>
>> cp -r /opt/$USER1/test /backup/$USER1
>> cp -r /opt/$USER2/test /backup/$USER2
>
> $ for user in one two three four; do echo $user; done
> one
> two
> three
> four
>

or if the list of users is in a file, one per line

$ cat file
roland
dany
kevin
$
$ cat file | while read name
do
     something $name
done

Tony




More information about the CentOS mailing list