I'm trying to generate random pass of the users created by a text file in a bash script and then saving those passwords into a text file.. That's how I'm doing.. It works fine and creates user from text file and output the password as well well to lol file, but the passwords for created users wont work.Here's my code, any help regarding that would be appreciated..while read line || [ -n $line ] # protect against no newline for last linedo name=$linepass=$(cat /dev/urandom| tr -dc 'a-zA-Z0-9' | fold -w 8| head -n 1 >> lol)sudo useradd $name -msudo usermod -p $(echo $pass | openssl passwd -1 -stdin) $nameecho The user - $name - has been created!done < $fname # double-quote fname echo
Trying to generate random pass for users and saving them in a file
bash
The return value of command substitution is the stdout of the subshell.In the following line, you've redirected the output to the file lol within the subshell.  therefore there is no return value for you to store in the variable pass:pass=$(cat /dev/urandom| tr -dc 'a-zA-Z0-9' | fold -w 8| head -n 1 >> lol)You could either split the following line into two as follows:pass=$(cat /dev/urandom| tr -dc 'a-zA-Z0-9' | fold -w 8| head -n 1)echo $pass >> lolOr use tee -a:pass=$(cat /dev/urandom| tr -dc 'a-zA-Z0-9' | fold -w 8| head -n 1 | tee -a lol)