I'm trying to modify a script that read usernames/password from a file which is like this:
for row in `cat $1`
if [ $(id -u) -eq 0 ]; then
It would be easier to split the two fields as you read each line. You can do that with
read. It's also better to use a
while loop here (a for loop requires to play with
$IFS and it would also load the entire file in memory):
#!/bin/bash if [ "$EUID" -ne 0 ]; then echo >&2 "You are not root" exit 1 fi while read -r username password; do # do the useradd stuff here done < "$1"
Notice that I also changed
$(id -u) to
$UID which should be faster since it does not invoke an external program.