By Cloudy_Cat
So my script is one of those make-user-scripts, making a bunch of directories in the home folder and copying some files over into the new directories.
However, part of the thing my script need to do is check the home folder if a username matches with a directory which already exists.
e.g. if the username ‘user1’ has a directory in the home folder under the same name, it will prompt the user if he/she wants to keep or delete the directory (and its contents) before moving on with the script.
Here is the part of the script which does this:
cat $1 | while read line; do
username=$line
if [ -d $4/$username ];
then
echo WARNING username $username already has a directory.
read -p "Would you like to KEEP or DELETE?" answer
if [ "$answer" == "DELETE" ];
then
rm -fr $4/$username
elif [ "$answer" == "KEEP" ];
then
echo "Keeping directory $username"
else
echo "Unknown answer assuming keeping file"
fi
fi
done
Where:
$1 = path to the username_list file
$4 = path to the home directory for user creation
Now as the thread title suggests, the problem is the read line is not prompting for user input.
I suspect it may be something to do with the fact I’m piping via the while loop, but I don’t know I’m just a newbie to all this. Can anyone suggest a solution to this?
Thanks in advance,
Cloudy
…read more
Source: FULL ARTICLE at The UNIX and Linux Forums