Skip to content

Instantly share code, notes, and snippets.

@SametSahin10
Created May 26, 2020 14:52
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Bash script to create numbered directories from a single command.
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