Skip to content

Instantly share code, notes, and snippets.

@SametSahin10
Created May 26, 2020 14:52
Show Gist options
  • Save SametSahin10/1a1e1bc1c9f73c449a3c66eebb480302 to your computer and use it in GitHub Desktop.
Save SametSahin10/1a1e1bc1c9f73c449a3c66eebb480302 to your computer and use it in GitHub Desktop.
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