Skip to content
Advertisement

Reading username and password from file

I’m looking at a away of reading the username and password of a file and inputing those to either add user or delete user.

EG: I have a file named ‘userlist’ with the following content with this format:

JavaScript

What I don’t understand completely is how to use BASH script to add these accounts.

What I have so far is this:

JavaScript

Alright, what I don’t understand is how to read each word line by line and input the username and password to add a new user or delete an existing user.

The program is ment to read the whole file and add each user with there corrosponding password. If delete is chosen then it deletes each user within the file.

I’m new to BASH so any help would be greatyl appreciated.

Advertisement

Answer

awk perfectly feets your needs.

See this example:

JavaScript

Awk stores usernames in $1 and passwords in $2 (first and second column).

You can use pipelines to execute the strings you get from awk as commands:

JavaScript
Advertisement