The IF condition for Linux programming bash

Source: Internet
Author: User


Bash Script Programming:
Programming Languages:
Sequential execution
Select Execute
Loop execution

Select Execute:
If judging condition
Then
Branch code with true condition
Fi

if judgment condition; Then
Branch code with true condition
Else
The condition is a false branch code
Fi

Write a shell if the user does not exist, add the user, and the existing information is printed.


#!/bin/bash

If [$#-lt 1]; Then
echo "At least one"
Exit 1
Fi

If ID $ &>/dev/null; Then
echo "$ exixts"
#exit 0 indicates success
Exit 0
Else
Useradd $

[$?-eq 0] && echo "$" | passwd--stdin $ &>/dev/null && Exit 0 | | Exit 1
Fi

Usage
chmod +x a.sh
SH a.sh xiaoming

This article is from the "Liang blog" blog, make sure to keep this source http://7038006.blog.51cto.com/7028006/1827893

The IF condition for Linux programming bash

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.