Bash script to create numbered directories from a single command.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create_numbered_directories() { | |
nameOfDirectories=$1 | |
indexOfLastFile=$2 | |
# Variable to hold the number of errors that may possibly occur | |
# while creating directories | |
numOfErrors=0 | |
for i in $(seq 1 $indexOfLastFile) | |
do | |
echo creating directory: $nameOfDirectories-$i | |
mkdir "$nameOfDirectories-$i" | |
if [ $? -ne 0 ]; then ((numOfErrors+=1)); fi | |
done | |
if [ $numOfErrors -gt 0 ]; then | |
echo Errors occured creating one or more directories | |
else | |
echo Directories created successfully | |
fi | |
} | |
create_numbered_directories "$1" $2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment