`
venceinfo
  • 浏览: 36587 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

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

 

分享到:
评论

相关推荐

    shell 编程小结

    shell 编程小结

    shell 编程指南pdf

    1.10 小结 13 第2章 使用find和xargs 14 2.1 find命令选项 14 2.1.1 使用name选项 15 2.1.2 使用perm选项 16 2.1.3 忽略某个目录 16 2.1.4 使用user和nouser选项 16 2.1.5 使用group和nogroup选项 16 2.1.6 按照更改...

    Bash Shell脚本入门小结

    摘要:对于经常使用Shell命令的朋友来说,掌握基本的Shell脚本语法就可以着手编写Shell脚本了。因此,在文档中,鄙人以介绍Shell语法为重点,必要之处,附以命令、语法的使用说明,所谓“寓情于景、寓理于事”,可以...

    shell编程中的字符串截取方法小结

    一、Gnu Linux shell 截取字符变量的前8位,有方法如下: 1.expr substr “$a” 1 8 2.echo $a|awk ‘{print substr(,1,8)}’ 3.echo $a|cut -c1-8 4.echo $ 5.expr $a : ‘\(.\\).*’ 6.echo $a|dd bs=1 count=8 2>...

    Shell编程下的AWK语法小结

    shel awk 学习:Shell编程下的AWK语法小结

    unix--shell的一些特殊参数小结

    Unix Shell 编程一些常用但是又容易忘记的东西。 描述参数输入、回车换行、以及算法。

    LINUX与UNIX SHELL编程指南(很全)

    1.10 小结 13 第2章 使用find和xargs 14 2.1 find命令选项 14 2.1.1 使用name选项 15 2.1.2 使用perm选项 16 2.1.3 忽略某个目录 16 2.1.4 使用user和nouser选项 16 2.1.5 使用group和nogroup选项 16 2.1.6 按照更改...

    Seacms代码审计小结(后台多处getshell)1

    在框架中,有很多是写的是以 txt 结尾的件,这种直接读是法以 php 来解析,但是如果找到处件包含的漏洞,让他包含的是这种我们可以修改的件,那就也可以造成代码

    Linux与unix shell编程指南

    1.10 小结 13 第2章 使用find和xargs 14 2.1 find命令选项 14 2.1.1 使用name选项 15 2.1.2 使用perm选项 16 2.1.3 忽略某个目录 16 2.1.4 使用user和nouser选项 16 2.1.5 使用group和nogroup选项 16 2.1.6 按照更改...

    python中执行shell命令的几个方法小结.docx

    python中执行shell命令的几个方法小结.docx

    Shell脚本if else语句小结

    代码如下: <?...if (isset($_GET[“q”])) {  search(q); } else {  //do nothing ...在sh/bash里可不能这么写,如果else分支没有语句执行,就不要写这个else,就像这样: ...if test $[2*3] -eq $[1+5];

    绝版经典《Linux与UNIX Shell编程指南》

    1.10 小结 13 第2章 使用find和xargs 14 2.1 find命令选项 14 2.1.1 使用name选项 15 2.1.2 使用perm选项 16 2.1.3 忽略某个目录 16 2.1.4 使用user和nouser选项 16 2.1.5 使用group和nogroup选项 16 2.1.6 按照更改...

    shell教程-30章,下了之后会让你大吃一惊,相当好

    1.10 小结 13 第2章 使用find和xargs 14 2.1 find命令选项 14 2.1.1 使用name选项 15 2.1.2 使用perm选项 16 2.1.3 忽略某个目录 16 2.1.4 使用user和nouser选项 16 2.1.5 使用group和nogroup选项 16 2.1.6 按照更改...

    LINUX与UNIX SHELL编程指南 高清PDF

    1.10 小结 13 第2章 使用find和xargs 14 2.1 find命令选项 14 2.1.1 使用name选项 15 2.1.2 使用perm选项 16 2.1.3 忽略某个目录 16 2.1.4 使用user和nouser选项 16 2.1.5 使用group和nogroup选项 16 2.1.6 按照更改...

    用Shell判断字符串包含关系的方法小结

    以下给出一些shell中判断字符串包含的方法,来源程序员问答网站 stackoverflow 以及segmentfault。 方法一:利用grep查找 strA=long string strB=string result=$(echo $strA | grep ${strB}) if [[ $result != ]] ...

    Linux与Unix Shell编程指南(PDF格式,共30章)

    1.10 小结 13 第2章 使用find和xargs 14 2.1 find命令选项 14 2.1.1 使用name选项 15 2.1.2 使用perm选项 16 2.1.3 忽略某个目录 16 2.1.4 使用user和nouser选项 16 2.1.5 使用group和nogroup选项 16 2.1.6 按照更改...

    Linux shell 编程

    1.10 小结 13 第2章 使用find和xargs 14 2.1 find命令选项 14 2.1.1 使用name选项 15 2.1.2 使用perm选项 16 2.1.3 忽略某个目录 16 2.1.4 使用user和nouser选项 16 2.1.5 使用group和nogroup选项 16 2.1.6 按照更改...

    绝版经典 LINUX与UNIX SHELL编程指南 PDF 高清版 [16.3M]

    第十五章 小结 第四部分 基础SHELL编程 第十六章 SHELL脚本介绍 第十七章 条件测试 第十八章 控制流结构 第十九章 SHELL函数 第二十章 向脚本传递参数 第二一章 创建屏幕输出 第二二章 创建屏幕输入 第二三...

    LINUX与UNIX SHELL编程指南

    第十五章 小结 第四部分 基础SHELL编程 第十六章 SHELL脚本介绍 第十七章 条件测试 第十八章 控制流结构 第十九章 SHELL函数 第二十章 向脚本传递参数 第二一章 创建屏幕输出 第二二章 创建屏幕输入 第二三章 调试...

    linux shell 编程教程

    1.10 小结 13 第2章 使用find和xargs 14 2.1 find命令选项 14 2.1.1 使用name选项 15 2.1.2 使用perm选项 16 2.1.3 忽略某个目录 16 2.1.4 使用user和nouser选项 16 2.1.5 使用group和nogroup选项 16 2.1.6 按照更改...

Global site tag (gtag.js) - Google Analytics