zoukankan      html  css  js  c++  java
  • 常用shell脚本(持续更新中)

    1. 写一个shell脚本来得到当前的日期,时间,用户名和当前工作目录。

    答案 : 输出用户名,当前日期和时间,以及当前工作目录的命令就是logname,date,who i am和pwd。

    #!/bin/bash 
    echo "Hello, $LOGNAME" 
    echo "Current date is `date`" 
    echo "User is `who i am`" 
    echo "Current directory `pwd`"

    给权限并运行它

    root@ubuntu:~# vim userstats.sh
    root@ubuntu:~# chmod 755 userstats.sh 
    root@ubuntu:~# ./userstats.sh

    输出结果

    2.写一个shell脚本,进行两个数字的相加,如果没有输入参数就输出错误信息和一行使用说明

    #!/bin/bash
    if [ $# -ne 2 ]
    then
       echo "Usage - $0 x y"
       echo "Where x and y are two num for which I will print sum"
       exit 1
    fi
    
    echo "sum of $1 and $2 is `expr $1 + $2`"

    输出结果

  • 相关阅读:
    总结
    总结
    总结
    总结
    合作成功案例
    本周作业
    上周作业
    本周总结
    本周作业
    分答
  • 原文地址:https://www.cnblogs.com/chenxiaomeng/p/10118859.html
Copyright © 2011-2022 走看看