Created
May 26, 2020 14:52
-
-
Save SametSahin10/1a1e1bc1c9f73c449a3c66eebb480302 to your computer and use it in GitHub Desktop.
Bash script to create numbered directories from a single command.
This file contains hidden or 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