hello,
I try to add users from a text file with this form:
username:groupename:homedir
first i extract data which is separated by ":"
then i use useradd to add users/groups.
but,,, my code doesn't works :
#!/bin/bash
echo "give me a text file: "
read dir
# control if the file is valid
if [ -f $dir ]
then
for user_dets in $(dir) #loop and extract data
do
user= echo "$user_dets" | awk -F\: '{print $1}'
group= echo "$user_dets" | awk -F\: '{print $2}'
home= echo "$user_dets" | awk -F\: '{print $3}'
useradd -g "$group" -d "$home" $user
done
else
echo "file is not valid"
fi
I found this code which probably do the same as awk 'also doesn't works':
user = $(echo $ligne | cut -d':' -f1)
Can someone help me please?