1.shell 是命令解析器,将用户输入的指令转化为机器可以运行的程序
2.利用vim编辑器shell格式:
#!/bin/bash ☆
#comments 注释
your command go here 命令
3.编辑完毕将.sh文件改为可执行文件再执行 chomad
4.例子
(1).
#!/bin/bash
a="hello world"
echo $a echo :输出
(2).
#!/bin/bash
for a in $1 $2 $3 for循环语句
do
mkdir $a
cd $a
touch $a.txt
echo “hello$a”>$a.txt >覆盖 >>添加
cd ..
done
(3).
#!/bin/bash
echo “#include<stdio.c>”>hello.c
echo"int main ()">>hello.c
echo"{">>hello.c
echo' printf("hello world\n");'>>hello.c
echo"}">>hello.c
gcc hello.c -o hello
./hello 生成./hello为一个命令
(4).
#!/bin/bash
hello="hello world"
a( )
{echo "hello"}
b( )
{echo "world"}
a
b
echo $hello
(5)
#!/bin/bash.
dir="/root/cyl/11.07" 路径
file="/root/cyl/11.07/a.c" 文件
if [ -d $dir ];then -d 查看路径 if 条件语句
echo "$dir"
fi
if
[ -f $file ];then -f 查看文件
echo "$file"
fi
(6).
#!/bin/bash
read key read 输入读写
case "$key" in 条件语句
[A-Z] ) echo “upperletter”;;
[a-z] ) echo "lowerletter";;
[0-9] ) echo "number";;
esac
5.默认变量
$# 传入脚本的命令行参数个数 $* 所有命令参数值 $0 命令本身 $1 第一个命令行参数...