shell小结(5)

-------------------------------------------------------------------------------------------

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()
{
}
-------------------------------------------------------------------------------------------

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值