I'm trying to write a bash shell script that will read the data from a given (as an argument) file, and for each row in the file, make a sub-directory under the given (as an argument) directory.
The script is named studentDir
and the input file is named studentInfo.txt
.
Here is two lines from it:
Sara Smith Freshman Marketing
James Lucas Junior Engineering
On the command line the user would write the script name, the txt file name, and the directory where the new directories should be stored. I think it would be like this:
$ studentDir studentInfo.txt .
Which will create the sub-directories in the current directory.
The directories should be named LLLLFF.
For example:
SmitSa
LucaJa
(The other info from the input file is not needed)
I think to get the names I would use:
DIRNAME=$(cut -d' ' -f2 | cut -c1-4 ; cut -d' ' -f1 | cut -c1-2)
mkdir "$DIRNAME"
But I'm not sure what command would create a directory for each row, and how I could do it recursively for each one.
cut
command as the directory name? P.S. Recursion is rarely the answer (and in this case it is indeed not). Recursion is evil. Stay away from recursion :-)