Linux Shell脚本的简单使用

脚本第一行一定是#!/bin/bash

1、脚本执行时输出到命令行  echo “this is me” 

               printf %s %c %d %f

2、脚本执行时从命令行读取输入read var    脚本内执行命令`ls -l “/boot”`

3、设置变量name=wu  使用变量${wu}  删除变量unset wu   只读变量readonly wu

4、定义数组namearray=("an" "bing" "cun")  使用变量${namearray[0]}

5、脚本参数:参数个数$#  第一个参数$1  脚本名$0  所有参数$*或者$@  当前进程ID: $$  退出状态$?  后台最后一个进程ID: $!

6、运算符:算术+-x/%  关系  布尔  逻辑  字符串  文件测试(-f -d -e -r -w -x)

7、定义函数fun(){}  使用函数fun  使用带参数函数fun v1 v2 v3

8、重定向command > file  command >>file  command < file  command > file 2>&1  0表示标准输入,1表示标准输出,2表示错误输出。/dev/null

9、包含文件. ./file    source ./file

posted on 2019-08-05 16:39  BI0Swu1y  阅读(194)  评论(0编辑  收藏  举报