About adding users from a text file using bash

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?

Maybe. You should post WHAT doesn't work. I guess you're using a recent version of bash ?
You read in a file name, but never read FROM that file. I bet you get a "command not found" error for the $(dir) , and user_dets are never assigned to.
Try e.g.

while IFS=":" read user group home
  do useradd ...
  done < $dir

and report back.

How about this?

# control if the file is valid
if [ -f $dir ]
then
  awk -F: '{ printf("useradd -g %s -d %s %s\n", $2, $3, $1) }' $dir > tmp.shl
  chmod +x tmp.shl
  ./tmp.shl
else
  echo "file is not valid"
fi

This is a modification of the last lines of your code, be sure to put back the ones I left out.