September 13 Tenth session Linux shell script programming Basics

Source: Internet
Author: User

Tag: blank linux target password null

Homework

1, request to add a user newuser, if it already exists then display "The user USERNAME is exists", if present, add it and set its password to "[email protected]"

#!/bin/bash
#
Username=newuser1
if! ID $username &>/dev/null;
Then AddUser $username
echo $username | passwd--stdin "[email protected]" &>/dev/null
echo "ADD user $username sucessfully."
Else "The user is exists."
Fi
Exit

2, write a script, if a path does not exist, it will be created as a directory, otherwise show that it exists, and display the content type

#!/bin/bash
#
Path= "/tmp/testdir"
if [!-e $path];then
if [!-D $path];then
mkdir $path
echo "Make directory $path sucessfully."
else echo "$path has been exists."
Fi
else echo "$path has been exists."
Fi

September 13 Tenth session Linux shell script programming Basics

Related Article

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.