I am learning for an approaching exam and I've been learning more and more about bash.
One of the question goes as follows:
- Get at least 11 arguments (else, give an stderr output and exit)
- The first argument is going to be a directory
- The other arguments shall become .txt files in that directory
I can't seem to figure out how to create an N amout of text files ( N=number of arguments).
I have already tried a for loop like in the shown code, but i cannot seem to really figure it out. I should mention that this is shell is being ran in a Linux Subsystem on Windows 10 ( if it's in any way important ).
#!/bin/bash
count=$#
if [ $# -lt 11 ]
then
>&2 echo "Didn't receive enough arguments."
exit 1
fi
if [ ! -r $1 ]
then
echo "Creating file..."
mkdir $1
echo "...done."
fi
cd $1
for i in {1..$count}
do
echo $i
echo >> $i.txt
done
The output should be simple, a directory with the name of $1, in it, N amout of text files. Something similar to this:
-$2.txt
-$3.txt
-$4.txt
.
.
.
-$N.txt