Hello guys im new in ubuntu,so i have an assigment to make a script that makes new user from text file.i have some problems and cant extract from text.may u help me?thanks a lot. Here's my code:

while  [ $Username! = "" ]
        Username=`grep "Username00$num" $Path | cut -f2 -d:`  #Username   
        Password=`grep "Password" $Path | cut -f2 -d:`      
        Group=`grep "Group" $Path |cut -f2 -d:`              #Group   

        groupadd $Group

the problem is on first line,i cant paste the whole code cause is 160 lines.

  • 1
    You could use Ubuntu Pastebin for the full script... and Adding the error it gives would be helpful – Wilf Dec 30 '13 at 17:49

The main problem in your first line is the incorrect whitespace - the "not equal" needs to be a single operator like != rather than ! =, and the ! needs to be separated from the variable preceding it. You should also quote the variable in any string comparisons, in case it contains whitespace

while  [ "$Username" != "" ]

If you post a sample of the text file there's almost certainly a better way to read the username / password / group fields (instead of using lots of grep and cut commands).


I got a similar problem (homework)

I need to create new users using details taken from a text file, and I can only use shellscripting and awk.

The text file got this format


the field separator is ":"

I would than any help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.