-------------------------------------------------------------------------------------------
shift关键字
#!/bin/bash
fun()
{
echo $1
shift
echo $1
}
fun a b c
-------------------------------------------------------------------------------------------
function wrap
{
#set -x
typeset func_name="wrap"
typeset ret=""
#执行业务调用的脚本或者命令
$@
ret=$?
return ${ret}
}
---------------------------------------------------------------------------------------------
grep -c 统计找到的行数
if [ `echo "$0" |grep -c "/" ` -gt 0 ];then
cd ${0%/*}
fi
----------------------------------------------------------------------------------------
数组的长度:
typeset length
length=${#filearray[@]}
-------------------------------------------------------------------------------------------
由端口:netstat -anp -->找到进程,然后ps-ef 找到用户
-------------------------------------------------------------------------------------------
中文编码范围:[\\u4e00-\\u9fa5]
-------------------------------------------------------------------------------------------
//利用IFS处理文件
IFS=Internal Field Separator
用在shell中,控制分隔符,在for。。in的语法中很有用。
回车的设置应该使用IFS=$'\n'的格式 或IFS=$"\n"
如:
#!/bin/bash
name=aa:bb:cc:dd
for i in $name
do
echo $i
done
输出为:aa:bb:cc:dd
#!/bin/bash
name=aa:bb:cc:dd
IFS=":"
for i in $name
do
echo $i
done
输出为:aa
bb
cc
dd
循环读取文件的每一行
#!/bin/bash
IFS=$'\n'
for line in $(cat text.txt)
do
echo $line
done
-------------------------------------------------------------------------------------------
PS2 is called the secondary prompt string; its default value is >.
It is used when you type an incomplete line and hit RETURN, as an indication that
you must finish your command. For example, assume that you start a quoted string
but don't close the quote. Then if you hit RETURN, the shell will print > and wait
for you to finish the string:
-------------------------------------------------------------------------------------------
BASH 中要求函数的定义必须在函数使用之前,这是和 C 语言用头文件说明函数方法的不同。
定义的三种方式:
funtion fun1()
{
}
#后面可以没有()
funtionc fun1
{
}
#后面必须有()
fun1()
{
}
-------------------------------------------------------------------------------------------