fun shell scripts
im trying to get a grasp on how to make shell scripts...
my current experiment is to take for example folder ./1 has 25 files 1.examp 2.examp 3.exap.... and so on i wanna just for the hell of it take each file and make 1000 copies of it... so in the end folder ./1 will have 25,025 files in it (dont forget the original 25...) heres my thoughts Code:
#start with a |
for i in $(ls 1);do a=0;while [ "$a" -ne "1000" ];do cp "1/$i" "1/$i-copy-$a";let a++;done;done
: ) |
Or slightly shorter notation: "for ((i=1;i<10;i++)); do doSomethingWith${i}; done".
|
can you break down the code so i learn it thats the point not to run it
|
Quote:
To give you a head start, the example given is a "for loop"--one of many kinds of loops that are a staple of any programming language. In Bash, the basic syntax is: for <conditions>; do <task1> <task2> <task3> . . done "conditions" can be a variety of things. In the 1st example, the construct: for i in $(ls 1) translates as follows: run the ls command on the directory "1" take this list and iterate through it, assigning each successive filename to the variable "i" In this case, the loop finishes simply when it reaches the end of the list. |
All times are GMT -5. The time now is 09:13 PM. |