Linux Shell脚本基础学习笔记
shell 脚本实践
1,识别符
#! /bin/bash
#! /bin/sh
2,执行脚本
chomd + x ./test.sh #赋予可执行权限
./test.sh #执行脚本
/bin/sh test.sh
/bin/php test.php
shell变量
your_name="your,name" #定义变量
for file in 'ls /etc' #循环显示出etc目录下的文件名
1使用变量
echo $your_name #打印变量
echo ${your_name}
2只读变量
#!/bin/bash
myName="hjh"
readonly myName
myName="new name" #此处会报错,因为变量变只读
3删除变量
unset variable_name #不能删除只读变量
4变量类型
局部变量
环境变量
shell变量
5shell字符串
str="abcdef"
echo ${
#str} #输出字符串长度
echo ${str:1:4} #从下标左到右,index为1,截取4个
str="hello my name is hjh"
echo 'expr index "$str" is'
6shell数组
array=(1 2 3 4 5 6)
array[0]=4
array[1]=5
array[2]=6
echo ${array[@]