I'm messing around with scripting, I am able to create a script which when run prompts me for a name for a new dir, creates it then creates several files, echoes lines out, then deletes it all.
What I would like to do is morph it slightly so it creates and names the directory all by itself!
Seems a pointless exercise I know, but messing around with it is the best way I learn.
Here is my current script:
#!/bin/bash
echo "Give a directory name to create:"
read NEW_DIR
ORIG_DIR=$(pwd)
[[ -d $NEW_DIR ]] && echo $NEW_DIR already exists, aborting && exit
mkdir $NEW_DIR
cd $NEW_DIR
pwd
for n in 9 8 7 6 5 4 3 2 1 0
do
touch file$n
done
ls file?
for names in file?
do
echo This file is named $names > $names
done
cat file?
cd $ORIG_DIR
rm -rf $NEW_DIR
echo "Goodbye"
9 8 7 6 5 4 3 2 1 0
in your code can be shortened to{9..0}
and you might as well replace the wholefor
loop withtouch file{9..0}
.