美文网首页
bash小结

bash小结

作者: alex_zn | 来源:发表于2018-07-19 14:37 被阅读0次

Shell脚本编程

shell 标识第一行 #!/bin/sh

变量
v1="macos"
echo $v1
v2="windows"
echo $v2
字符串

单引号字符串的限制:

  • 单引号里的任何字符都会原样输出,单引号字符串中的变量是无效的
  • 单引号字串中不能出现单引号(对单引号使用转义符后也不行)
str='this is a string'
双引号
name="zhanshan"
str="hello,$name"
拼接字符串
fullName="$name,$str"

条件变量

# if
if condition
then
    command1 
    command2
    ...
    commandN 
fi

#if else 

if confition
then
    command
eles
    command
fi

#for循环
for item in item1 item2...itemN
do
    command
done
#自增
for(c1;c2;c3)
do
    commeand
done
#循环
while condition
do
    command
done

数组

arr1=(A,B,"C",$val)

函数

testFunc1() {
    echo "fun1"
}
testFunc2() {
    echo "第一个参数$1"
    echo "第二个参数$2"
}

相关文章

  • bash小结

    Shell脚本编程 shell 标识第一行 #!/bin/sh 变量 字符串 单引号字符串的限制: 单引号里的任何...

  • bash小结

    linux支持的shell: *if判断[ a ] 条件a两侧应有空格 注意: 一,变量赋值时,“=”左右两边都不...

  • bash数组小结

    Bash Shell只支持一维数组。 数组声明方式:bash中数组可以不用声明,直接按照数组赋值方式给数组赋值,b...

  • Linux中执行shell脚本的4种方法(转)

    bash shell 脚本的方法有多种,现在作个小结。假设我们编写好的shell脚本的文件名为hello.sh,文...

  • bash脚本内部变量

    bash脚本内部变量 $BASH bash的程序文件的路径,如/bin/bash $BASH_ENV 该环境变量保...

  • 2020-01-08 gstreamer+graphviz

    @ bash @ c file @bash

  • Hadoop安装指南

    sudo vi .bash_profile vi ~/.bash_profile~/.bash_profile s...

  • [Bash] Bash CheatPaper

    赋值语句 条件判断 字符串 字符串长度 字符串打印并补空格 获取文件名 从运行结果可以看到,使用该命令,可以提取出...

  • React Native 配置android 环境变量

    1、创建 .bash_profilecd ~touch .bash_profile2、查看 、编辑 .bash_p...

  • python 更改默认版本(3.7)

    终端打开.bash_profile文件open ~/.bash_profile 修改.bash_profile文件...

网友评论

      本文标题:bash小结

      本文链接:https://www.haomeiwen.com/subject/icdtmftx.html