Linux shell脚本(编辑中)

参考视频:老男孩
shell是一个程序,是用户和Linux内核沟通的桥梁

shell脚本第一行

#!/bin/bash
其中#!不是注释,而是告诉操作系统将执行此脚本所用的解释器的名字。

配置vim更适应shell编写

:syntax on
:set hlsearch
:set tabstop=4
:set autoindent

可以去掉冒号,添加到~/.vimrc中

helloWorld

#! /bin/bash
# helloworld
hello world!
# 文件名为helloworld

运行:.helloworld

运行shell

  1. .脚本名
  2. 解释器 脚本名(如 sh 脚本名 或者 bsah 脚本名)

变量和常量

  • 变量、常量定义
    变量名 = 值
    常量的名字一般大写,实际上变量和常量是一样的
  • 读取变量
    $变量名

特殊字符

`反引号:命令中执行命令

条件判断 if

# commands为某个命令
if commands; then
     commands
[elif commands; then
     commands...]
[else
     commands]
fi

逻辑操作符

  • 与 &&
  • 或 ||
  • 非 !

读取键盘输入

read [-options] 变量名1 变量名2 ……

循环

while commands; do commands; done

支持break和continue

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值