• 脚本进阶


    if语句

    1、编写脚本/root/bin/createuser.sh,实现如下功能:使用一个用户名做为参数,如果指定参数的用户存在,就显示其存在,否则添加之;显示添加的用户的id号等信息
    #!/bin/bash
    #
    #********************************************************************
    #Author:		luoqixiong
    #QQ: 			427822450
    #Date: 			2018-08-30
    #FileName:		createuser-if_73.sh
    #URL: 			http://www.cnblogs.com/lqynkdcwy
    #Description:		The test script
    #Copyright (C): 	2018 All rights reserved
    #********************************************************************
    read -p "Please input username: " UserName
    #id $UserName &> /dev/null && echo "$UserName" is Already exist || { useradd $UserName ; id $UserName; echo "$UserName" created success; }
    id $UserName &> /dev/null
    if [ "$?" = 0 ] &> /dev/null;then
    	echo "$UserName" is Already exist
    else 
    	useradd $UserName
    	id $UserName
    	echo "$UserName" created success
    fi	
    
    2、编写脚本/root/bin/yesorno.sh,提示用户输入yes或no,并判断用户输入的是yes还是no,或是其它信息
    #!/bin/bash
    #
    #********************************************************************
    #Author:                Luo QiXiong
    #QQ:                    427822450
    #Date:                  2018-08-29
    #FileName:             yesorno_73.sh
    #URL:                   http://www.cnblogs.com/lqynkdcwy
    #Description:          The test script
    #Copyright (C):         2018 All rights reserved
    #********************************************************************
    read -p "Please input yes or no: " ANS
    if [[ $ANS =~ ^[Y|y]([E|e][S|s])?$  ]];then
            echo "You Choose yes"
    elif [[ $ANS =~ ^[N|n][O|o]?$  ]];then                                                                        
            echo "You Choose no"
    else 
            echo "You input wrong"
    fi
    
    3、编写脚本/root/bin/filetype.sh,判断用户输入文件路径,显示其文件类型(普通,目录,链接,其它文件类型)
    4、编写脚本/root/bin/checkint.sh,判断用户输入的参数是否为正整数

  • 相关阅读:
    Linux netstat命令详解
    createdb test时报global/pg_filenode.map不存在
    详解神经网络中的反向传播
    Android学习20--OpenGL的"mapPoints"
    C++指向常量的指针和常指针
    git合并别的分支某次提交或合并
    Java实现GB2312文件转UTF8文件
    Windows Opengl ES 环境搭建
    android学习19--Matrix.mapPoints作用
    无能量损失弹跳效果的实现
  • 原文地址:https://www.cnblogs.com/lqynkdcwy/p/9561146.html
Copyright © 2020-2023  润新知