shell脚本学习

Shell学习

我的博客

shell脚本学习

  1. 执行脚本报错“/bin/bash^M: 坏的解释器:没有那个文件或目录” 问题

    问题原因:在win下操作的时候,编辑了hello.sh文件,换行结尾是\n\r,但是在linux下是\n,所以会有多处来的\r

    解决方法:sed -i 's/\r$//' hello.sh

  1. echo是liunx的输出命令,#表示注释:
    Liunx已经定义的环境变量:$PATH 、$HOME 、$SHELL

  2. 写一个加法的shell脚本

    #!/bin/bash
    funWithReturn(){
    echo "输入第一个数字: "
    read aNum
    echo "输入第二个数字: "
    read anotherNum
    echo "两个数字分别为 $aNum 和 $anotherNum !"
    return $(($aNum+$anotherNum))
    }
    funWithReturn
    echo "输入的两个数字之和为 $?"

  3. 运行脚本

    #!/bin/bash
    echo "欢迎中国队!"
    java -jar data-sending.jar &

 

 

 

 

 

 

 

 

posted @ 2019-11-12 17:04  胄王  阅读(130)  评论(0)    收藏  举报