Shell scripting is a fickle beast. It may be worthwhile to find a beginner shell tutorial online to familiarize yourself with the basic utilities and syntax.
When you say
mkdir {1..5}
, the shell expands that into
mkdir 1 2 3 4 5
. When executed, the program
mkdir steps through each argument and creates a directory of the same name in the current directory.
When you say
cp filename {1..5}
, the shell expands that into
cp filename 1 2 3 4 5
. When executed, the program
cp attempts to copy all the arguments, except the last one, into the final argument. So what it tried to do was copy the file
filename and directories
1, 2, 3, and
4 into directory
5 (which isn't what you wanted to do). For completeness, the errors you got were because, being a potentially expensive operation,
cp doesn't copy directories by default. If you wanted to copy directories, you add the
-r
option to the command.
What you want is a
for
loop, as
@kryten2 suggested in your other post:
This iterates through every number in the sequence 1000–1100 and assigns the current number to the variable named
i, a common shorthand for "index". The
$i
expands/reads the variable, replacing it with the current number being handled. This is functionally equivalent to:
Bash:
mkdir 1000
mkdir 1001
mkdir 1002
...
So for your particular situation, you would want:
Bash:
for i in {1000..1100}; do cp infocard1.jpg $i/; done
Which does:
Bash:
cp infocard1.jpg 1000/
cp infocard1.jpg 1001/
cp infocard1.jpg 1002/
...
If the final argument is a directory (as above),
cp will copy the file into that directory with the same name. If you wanted to be more verbose, you could write something like:
Bash:
for ProductNumber in {1000..1100}; do
cp infocard1.jpg $ProductNumber/infocard1.jpg
done
This just scratches the surface of what you can do with shell scripts – the only limit is your imagination. Hopefully this whets your appetite enough to learn more on your own.