2020暑假第3周

  这周主要学的是shell脚本,大致内容有:

  创建脚本:#mkdir shells

  基本语法:#!/bin/bash

                    echo"Hello World!"

  运行方式:#sh hello.sh

             或:#chmod +x hello.sh

                     ./hello.sh或/绝对位置

  局部变量:# vim demo1.sh

                    #!/bin/bash

                    str="hello"

                    echo $str  或echo ${str} world

                    #sh demo1.sh

  环境变量:#env

                    #echo $HOME

                    创建环境变量:export MYENV=/root/lib/demo

                    生效:# sourse/etc/profile

  特殊字符:

              

   例:#!/bin/bash

         echo"第一个参数为:$1";

         echo"参数个数为:$#";

         echo"传递的参数作为一个字符串显示:$*";

          #sh demo2.sh aaa bbb ccc

  运算符:a+b:

           

              a×b:

                 echo 'expr $a * $b';

  if语句:

           

 for语句:

           

   函数:

              

         

         

原文地址:https://www.cnblogs.com/fengjingfei/p/13572162.html