Linux shell 脚本

来源:互联网 发布:java毕业设计免费下载 编辑:程序博客网 时间:2024/06/05 17:13

http://man.linuxde.net/

第一行#!指定执行shell的程序bash/sh/dash
#!/bin/bash
# 起到了注释的作用
echo

#! /bin/bash            echo this is a test     echo this 'is a test'   echo this "is a test"   echo "this 'is a test'" echo 'this "is a test"'echo "this is $UID" #变量可以直接用在""里claroja@ubuntu:~$ bash testthis is a testthis is a testthis is a testthis 'is a test'this "is a test"this is 1000

变量
赋值时不需要使用value=1使
echo $value=1
使用`或者$()进行命令赋值
value=
date`
value=(date)today=(date +%y%m%d)

重定向输出与管道
> >>
< <<

数学运算
1. expr
2. $[ operation ] 这个更加通用

退出状态码
$?
exit 可以指定退出状态码

状态码 描述 0 命令成功结束 1 一般性未知错误 2 不适合的shell命令 126 命令不可执行 127 没找到命令 128 无效的退出参数 128+x 与Linux信号x相关的严重错误 130 通过Ctrl+C终止的命令 255 正常范围之外的退出状态码

参考文献:
Linux命令行与shell脚本编程大全

原创粉丝点击