Home > OS >  A beginner's question, according to copy a shell script, bash out of the question, always can&#
A beginner's question, according to copy a shell script, bash out of the question, always can&#

Time:10-07

Script code
#!/bin/bash
The read - p "Enter The Users Password:" PASSWD \
For UNAME ` in cat users. TXT `
Do
Id $UNANME & amp;>/dev/null
If [$? - eq 0]
Then
Echo "Already Exists"
The else
Useradd $UNAME & amp;>/dev/null
Echo "$PASSWD" | PASSWD -- stdin $UNAME & amp;>/dev/null
If [$? - eq 0]
Then
Echo "$UNAME is Create success", "
The else
Echo "$UNAME is Create failure"
Fi
Fi
The done
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
An error "haha. Sh: line 4: syntax error near unexpected token ` do '
"

CodePudding user response:

Feel there are other characters, such as ^ M

CodePudding user response:

No ^ M: oh, I checked baidu many said the problem, but I don't have it

CodePudding user response:

I copied can directly use this script

CodePudding user response:

Users. TXT have? In the same directory

CodePudding user response:

Can answer technical points not? Without this file will be submitted to the wrong

CodePudding user response:

You this script problem is very big, there is something wrong with the three places

I mark yellow rim boxer has a problem, you probably are copied, is probably caused by the format of the Windows and Linux different

I revised without any problems, manual, please rewrite the three judgment, don't copy, manual override, normally for, and if the two fields should be and then or echo the color of the field is the same, rather than the original color, you might be the problem of Windows copied

CodePudding user response:

refer to 6th floor Empty_city_dreams response:
you this script problem is very big, there is something wrong with the three places

I mark yellow rim boxer has a problem, you probably are copied, is probably caused by the format of the Windows and Linux different

I revised without any problems, manual, please rewrite the three judgment, don't copy, manual override, normally for, and if the two fields should be and then or echo the color of the field is the same, rather than the original color, you might be the problem of Windows copied

Thank you oh, I'm a hand, playing to write again, a success

CodePudding user response:

reference 4 floor bitter mustard response:
users. TXT have? In the same directory

yes