Linux 脚本注解

来源:互联网 发布:高中英语单词读音软件 编辑:程序博客网 时间:2024/05/16 17:27

Linux 脚本注解

1.shebang

shebang= sharp + bang

sharp、hash(有时候也叫mesh)代表“#”;  bang代表“!”    shell脚本中需要引用shell:#!/bin/sh

2 # 代表注释

Shell 不会执行注释部分

3.获取字符串的长度

var=1234567890echo "${#var}"

4.识别当前的Shell版本

linux:/study_linux # clearlinux:/study_linux # echo $SHELL/bin/bashlinux:/study_linux # echo $0-bash

5.判断当前用户是否为root用户。

echo $UID

root用户的UID为0

6.文件描述符

0 : stdin (标准输入)

1 :stdout(标准输出)

2 :stderr(标准错误)

7.重定向(>)和追加(>>)

(>):采用先清空,后写入的方式

(>>):采用追加的方式

8.关于命令执行的成功和失败状态

当命令执行的时候,没行命令都会返回命令的状态,成功返回0,异常返回非0. 可以使用“$?”检查返回的状态.如下:

linux:/study_linux # lscheckforroot.sh  hexconversior.sh  variables.shlinux:/study_linux # echo $?0linux:/study_linux # ls +ls: cannot access +: No such file or directorylinux:/study_linux # echo $?2





0 0
原创粉丝点击