
01-06-2009
|
|
Shell programmer, author
|
|
|
Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,374
|
|
Quote:
Originally Posted by sera1711
Hi,
currently I'm trying to write a csh script that should do the following:
set i = 1
while ($i < 100) {
cp AAA BBB
set i = $i +1
}
where AAA is a string like this file.11.txt, file.21.txt, ...
and BBB is a string like this file_0001, file_0002, ...
Is it possible to generate the string AAA and BBB automatically from the variable i?
|
It's simple in a Bourne-type shell:
Code:
i=1
while [ $i -lt 100 ]
do
case $i in
?) nf=000$i ;;
??) nf=00$i ;;
???) nf=0$i ;;
esac
cp "file.$1.txt" "file_$nf"
done
You'll find it easier to write scripts in a standard shell and much easier to get help.
|