i need help with this homework. PLEASE
Assignment:
Create a directory "preFinal" in your home directory. Create empty files "a", "b", "c", etc in directory preFinal in the amount that match the number of directories preFinal*
This the code i have within Vi editor. But it is not working all the way. After runing bash about 10 times the letters jump from i to a random number and not in abc order. PLEASE TELL me how to do this.
#!/bin/bash
dir="preFinal"
if [ -d $dir ]; then
echo "dir exists, moving..."
i=0
for dir_bkp in `ls -lrt | grep "^d" | egrep "preFinal*" | awk '{print $NF}' | sort -nr`; do
next=$(echo "$dir_bkp" | sed 's/^.*\.//')
if [ $next == "preFinal" ]; then
next=-1
fi
next=`echo $next|sed 's/^0*//'`
((next++))
next=$(printf "%03d" $next)
#next="00$next"
echo $next
mv $dir_bkp $dir.$next
((i++))
else
mkdir $dir
touch $dir/a
fi
Bre/ GSW university / Unix CIS 3200 / Simon