1.创建一个脚本文件test.sh
root@pc# vi test.sh
//还有很多类型的shell脚本,bash/sh/csh/ksh/tcsh等
#this is just a sample programe for test //在脚本文件中#开头的行表示注释
#athor:wiselinksz
echo "this is just a sample programe for test" //在脚本文件中命令和变量不需要定义
a=123
b=321
echo $a //$表示引用,$a=123
if["$a"="$b"];then //if[判断条件];then...fi为流程判断语句
echo "a=b"
else
echo "a=!b"
exit(1);
fi
3.保存退出,给文件执行权限
root@pc# chmod a+x+w test.sh //a:可读,w:可写,x:可执行
脚本解释语言:perl/python/ruby/tcl/tk/lisp
root@pc# vi test.sh
2.脚本文件的内容
#!/bin/sh // 必不可少的一行,#!是一个幻数,后面跟着解释此脚本的shell路径//还有很多类型的shell脚本,bash/sh/csh/ksh/tcsh等
#this is just a sample programe for test //在脚本文件中#开头的行表示注释
#athor:wiselinksz
echo "this is just a sample programe for test" //在脚本文件中命令和变量不需要定义
a=123
b=321
echo $a //$表示引用,$a=123
if["$a"="$b"];then //if[判断条件];then...fi为流程判断语句
echo "a=b"
else
echo "a=!b"
exit(1);
fi
3.保存退出,给文件执行权限
root@pc# chmod a+x+w test.sh //a:可读,w:可写,x:可执行
4.执行文件
root@pc# ./test.sh
术语: #!是一个2字节的幻数,是用来指定一个文件类型的特殊标记,这种情况下指定该文件是一个可执行文件,后面跟的是解释这个脚本的路径,可以是shell或者任意一个通用程序,路径必须正确,否则会报错
shell种类:bash/sh/csh/ksh/tcsh...bash在上一命令有问题的时候继续执行下面的命令,sh则不会,当前自己登录的就是bash脚本解释语言:perl/python/ruby/tcl/tk/lisp