ProgrammingNotes
  • README
  • accounting会计学
  • Apache
  • ar
  • asciidoc
  • AssemblyLanguage汇编语言
  • authorization授权
    • 1.jwt
    • 2.oauth
  • C语言
    • C++
  • cache
  • Computer计算机相关
    • 1.reinstallSystem重装系统
    • 2.vhd
    • 3.bulidWeb建站
    • 4.computerOrganization计算机原理
  • config配置文件相关
  • ContainerTechnology
    • 1.docker
    • 2.kubernetes
  • cs计算机科学
    • 1.api
      • 1.1.restful
      • 1.2.graphQL
      • 1.3.openAPI
      • 1.4.swagger
    • 10.blockchain区块链
      • 10.1.bitCoin比特币
    • 11.characterEncoding字符编码
    • 12.map
      • 12.1.百度地图
      • 12.2.qgis
      • 12.3.openLayers3
      • 12.4.postGIS
    • 13.ai人工智能
    • 14.machineLearning机器学习
    • 15.ioT物联网
    • 16.microservices微服务
    • 17.serverless无服务架构
    • 2.uml
    • 3.designPattern
    • 33.compilation_tool编译工具
      • 33.1.gradle
      • 33.2.maven
    • 4.devOps
      • 4.1.ci
        • 4.1.1.jenkins
        • 4.1.2.github_actions
        • 4.1.3.team_city
      • 4.2.argoCD
    • 6.dataVisualization数据可视化
    • 7.abandonTechnology可放弃的技术
    • 8.bigData大数据
      • 8.1.streamComputing流计算
      • 8.2.edgeComputing边缘计算
    • 9.deepLearning
  • C#
  • db数据库
    • 1.sql
    • 2.noSQL
      • 2.1.redis
      • 2.2.mongoDB
      • 2.3.hbase
      • 2.4.etcd
    • 3.fileSystem文件系统
      • 3.1.fastDFS
      • 3.2.hdfs
    • 4.postgreSQL
    • 5.sqlserver
    • 6.MySQL
    • 7.oracle
    • 8.oceanBase
    • 9.influxDB
    • DatabaseSecurity数据库安全
    • pl/sql
  • Delphi
  • dorado
  • education
  • english
  • frontEnd前端
    • 1.html
      • 1.1.h5
      • 1.2.webSocket
      • 1.3.html2pdf
    • 10.1.wonder
    • 10.webGL
    • 2.w3C规范
      • 2.1.webAPIs
    • 3.css
    • 4.dom
    • 5.xhtml
    • 6.webAssembly
    • 7.ajax
    • 8.fetch
    • 9.picture
  • git
    • 1.gitbook
    • 2.svn
    • 3.github
    • 4.travis_ci
  • golang
    • go_cloud
    • go_crawler
    • goroutine
    • hydra
  • hardware
  • ios
  • java
    • 1.jvm
    • 2.java高级特性之多线程
    • 3.javafx
    • 4.java网络编程
    • 5.java类加载和反射
    • 6.jms
    • 7.java_cloud
    • 8.jsp
    • 9.spring
  • js
    • 1.npm
    • 13.mockJS
    • 19.bootstrap
    • 2.nodeJS
    • 25.echarts
    • 3.angular
      • 3.1.angularCLI
      • 3.2.angularMaterial
    • 4.react
      • 4.3.reactNative
      • 4.4.next
    • 5.vue
      • 5.1.vue-CLI
      • 5.2.vuex
      • 5.3.axios
      • 5.4.vue-router
      • 5.5.element-ui
      • 5.6.vueCore
      • 5.7.nuxt
    • 6.compilation_tool编译工具
      • 6.1.webpack
      • 6.2.parcel
      • 6.3.grunt
    • 7.lib第三方库
      • 7.1.jQuery
      • 7.2.lodash
    • TypeScript
      • 8.1.tslint
    • Deno
    • JS设计模式
    • ECMAScript
    • JS
    • JS6
    • NativeScript
    • RXJS
    • V8
  • linux
    • 1.vim
    • 2.shell
    • 3.shellScript
    • 4.ubuntu
    • 5.makefile
    • 6.centOS
  • markdown
  • markup_lang
    • JSON
    • YAML
  • math
    • 1.algorithm算法
    • 2.cryptology密码学
    • 3.computerGraphics计算机图形学
    • 4.dataStructure数据结构
  • MC消息通信
    • MQ消息队列
      • 1.kafka
      • 2.rabbitMQ
      • 3.redis
      • 4.activeMQ
      • 5.rocketMQ
      • 6.nats
    • MQTT
      • EMQ
    • RPC
      • gRPC
  • mobile
    • android
      • 1.kotlin
      • 2.weixin
      • 3.miniProgram
    • cordova
    • dart
    • flutter
    • ios
      • xcode
    • ReactNative
  • network网络
    • 2.ss
    • 3.http
    • 4.kcp
    • 5.nmap
    • 5G
    • 6.webCrawler
  • news重要新闻
  • Philosophy哲学
    • AnCoderPrepares程序员的自我修养
    • 软件工程的语录
  • php
  • popularizationOfScience科普
  • protocol
    • 1.rpc
  • python
  • readingNotes读书笔记
    • 1.profession专业笔记
    • 2.sql_Antipatterns
    • 3.unix_Network_Programming
    • 4.the_Docker_Book
  • rust
  • scriptingLanguage
    • 2.lua
    • 3.regularExpression正则表达式
    • 4.julia
    • 5.ruby
  • security安全
  • server服务器相关
    • nginx
    • OpenResty
  • software&tool软件和工具
    • 1.vscode
    • 11.plsqldev
    • 17.androidStudio
    • 3.虚拟机VirtualMachine
    • 4.jetBrains
    • 5.eclipse
    • 7.visualStudio
    • 8.office系列
  • softwaretest软件测试
    • JUnit
  • ssh&ssm
    • 2.hibernate
    • 1.spring
  • unix
    • hackintosh
    • mac
  • vr
  • windows
    • terminal&DOS
    • windows10
    • Wine
  • word一些术语
  • zztemp草稿
    • temp
    • temp4study
    • temp4studyLater以后再学的
Powered by GitBook
On this page
  • 3.shellScript
  • 3 常识
  • 三 基础
  • 未整理
  • 1 架构
  • 2 变量
  • 3 循环
  • 4 常用指令
  • 七 未整理

Was this helpful?

  1. linux

3.shellScript

3.shellScript

3 常识

3.1 执行shell script的两种方法

三 基础

未整理

  1. dirname $0:脚本所在的目录。可以方便的通过该目录来定位。

    1. dirname用于获取指定路径所在的目录。

    2. $0:表示当前运行的程序的名字,如果是在shell中则输出shell的名字,如果是在脚本中,则输出脚本的文件名。比如在bash中执行echo %0,输出的是“-bash”。

  2. #!:告诉系统其后路径所指定的程序即是解释此脚本文件的 Shell 程序

1 架构

2 变量

变量类型有三种:

  1. 环境变量

  2. 局部变量

  3. shell变量:由shell设置,即有环境变量,也有局部变量。常见的有$HOME、$PATH

    1. 参考:https://www.gnu.org/software/bash/manual/html_node/Shell-Variables.html

定义变量nameA=valueA(注意等号两边没有空格),使用变量$name或${name},声明为只读变量(不能再被修改)readonly name,删除变量(不能删除只读变量)unset name

# 普通变量
A=2
# 数组
a=(1 2 3 4 5)
echo ${a[0]}
echo ${a[-1]}
echo ${a[*]} 数组中所有元素
echo ${a[@]} 数组中所有元素
echo ${a[@]:0:3} 数组中1-3个元素
echo ${#a[@]} 数组中元素的个数
# 在curl中使用变量
url="www.example.com"
curl "$url"

set -x
file=file:///Users/xxx/temp/a
proto=file
curl --proto "=$proto" $file

3 循环

3.1 if else

if then的语法形如:

if condition
then
    command1 
    ...
fi

也可以写成一行,如if [ $(ps -ef | grep -c "ssh") -gt 1 ]; then echo "true"; fi

if then else的语法:

if condition
then 
    command1
else
    command2
fi

if else if:

if condition
then 
    command1
elif condition2
then 
    command2
else
    command3
fi

注意条件表达式必须放在方括号中。

3.2 for

for file in `ls /etc`

4 常用指令

  1. 等待

    1. wait:等待上一批或上一个脚本执行完(即上一个的进程终止),再执行wait之后的命令。

    2. sleep

      sleep 1    # 睡眠1秒
      sleep 1s   # 睡眠1秒
      sleep 1m   # 睡眠1分
      sleep 1h   # 睡眠1小时

七 未整理

  1. https://www.cnblogs.com/fhefh/archive/2011/04/15/2017613.html

Previous2.shellNext4.ubuntu

Last updated 8 months ago

Was this helpful?