In the following bash script if j=0000 how have I to change the following bash script to make dirs named 0001, 0002, ...? Actually it make dirs named 1, 2, 3
for i in *.jpg; do let j+=1 ; mkdir $j ; done
Thanks!
|
In the following bash script if j=0000 how have I to change the following bash script to make dirs named 0001, 0002, ...? Actually it make dirs named 1, 2, 3
Thanks! |
|||
|
|
|
Your current script uses only a decimal value - this obviously translates to the value without leading zeroes. You would have to pad the string to the length of 4 characters, with leading zeroes. You do this by using backticks As a result, you should have the full command:
Source: StackOverflow: bash - Padding zeros in a string (Obviously also see the further answers to that question, if you want a more in-depth solution, but this definitely works perfectly for this use case.) |
|||
|
|
|
Using bash, your best option is:
to create dirs with name If you want directories named
will do. If you only want odd number directory names
and so on... See Brace Expansion in the As FEichinger points out, you need to know in advance the number of directories. If you want a solution that is close to yours, but really safe and using more modern bash idiom:
|
|||||
|