Topic
See the following script:
#!/bin/bashgrep oldboy/etc/passwd &>/dev/nullreval=$?if [$REVAL-eq 0]then echo "Oldboy user already exists" else Useradd Oldboyfi
The above is a very simple creation of the corresponding user shell script code, is this simple script code can be more simple?
Reference Answer:
#!/bin/bashif grep-q oldboy/etc/passwdthen echo "Oldboy user already exists" else useradd Oldboyfi
User answer:
[' grep oldboy/etc/passwd|wc-l '-eq 1]&& echo OK | | Echo No
Note
Today is a day to accompany everyone's first day, look forward to your progress.
For questions and answers, please leave a comment in the blog comments section.
Index of the topic of the previous period
http://lidao.blog.51cto.com/3388056/1914205
This article is from the "Lee blog" blog, make sure to keep this source http://lidao.blog.51cto.com/3388056/1936557
Old boy Education daily-70th Day-shell script optimization points: