zoukankan      html  css  js  c++  java
  • Shell基本使用

    shell说明

    Shell 是一个用 C 语言编写的程序,它是用户使用 Linux 的桥梁。Shell 既是一种命令语言,又是一种程序设计语言。

    Shell 是指一种应用程序,这个应用程序提供了一个界面,用户通过这个界面访问操作系统内核的服务。

    Ken Thompson 的 sh 是第一种 Unix Shell,Windows Explorer 是一个典型的图形界面 Shell。

    shell使用

    第一个shell脚本

    echo "Hello world"
    

    可以创建test.sh文件,把上面的脚本写进去

    touch test.sh
    vi test.sh
    echo "Hello world"
    

    再执行./test.sh

    分配权限再执行:

    chmod 777 test.sh
    ./test.sh
    

    变量

    声明变量赋值

    myname="coydone"
    echo $myname
    echo ${myname}
    

    printf

    语法:

    printf  format-string  [arguments...]
    format-string: 为格式控制字符串
    arguments: 为参数列表。
    
    printf "%-10s %-8s %-4s
    " 姓名 性别 体重kg  
    printf "%-10s %-8s %-4.2f
    " 郭靖 男 66.1234 
    printf "%-10s %-8s %-4.2f
    " 杨过 男 48.6543 
    printf "%-10s %-8s %-4.2f
    " 郭芙 女 47.9876 
    

    循环

    • for

    语法:

    for var in item1 item2 ... itemN
    do
        command1
        command2
        ...
        commandN
    done
    

    案例:

    for loop in 1 2 3 4 5
    do
        echo "The value is:"$loop
    done
    for str in 'This' 'is' 'a' 'string'
    do
        echo $str
    done
    
    • while

    语法:

    while condition
    do
        command
    done
    

    案例:

    int=1
    while(( $int<=5 ))
    do
        echo $int
        let "int++"
    done
    
    • 死循环

    语法:

    while :
    do
        command
    done
    
    while true
    do
        command
    done
    
    for (( ; ; ))
    

    更多shell编程可以查看菜鸟教程:http://www.runoob.com/linux/linux-shell.html

    coydone的博客
  • 相关阅读:
    DLL注入实践
    程序编译保护机制
    加密配置文件总结
    PCL点云配准(3)
    PCL点云分割(3)
    ubuntu Ros环境halcon的一个程序
    opencv2/nonfree/nonfree.hpp:没有那个文件或目录
    深度图像计算三维点云
    利用深度学习的点云语义分割(一)
    3D 特征点概述(2)
  • 原文地址:https://www.cnblogs.com/coydone/p/13920421.html
Copyright © 2011-2022 走看看