Shell Script Learning report

Shell Script learning report

Contents :

1 Common uses of tools

Analysis the shell flowchart statement


2 vi editor



readlink


$0, $1, $2 and so on,这些符号其实可以这样来理解,$代表的是取某一个变量里面的值,而这些0,1,2数字代表的是这个指令的第几个参数的次数,而$是取出这个里面的内容,所以,


 对于flow chart这种类型的语句来说,以if语句来说,他的then这个应该是用来分隔if后面的list与true的情况下使用的,所以每一个带有if的内容后面需要用then来隔开内容,而让shell来认识if的作用域,它用了fi的方式来括起来.


As for the semicolon,It is necessary to locate it before then , which stands for a list of command should be list in this part,所以这个地方有一个需要注意的就是; indicates you have reached the end of this command after the semicolon where is a new command ,在if语句中为了能够tell the shell to interpret the else 、elif、then、fi都需要在之前的语句加上semicolon so that the result will appears.


3 对于shell中常用的符号"|" 的意思

    符号"|"的意思主要是指将"|"符号前面的结果作为一个参数给后面的指令使用,使用这个符号的指令应该首先从第一个指令开始分析,以前面指令的结果作为|后面指令的参数。举例分析:

场景:

在Android/framework/base/core/jni中搜索含有LOGD的文件,如果使用如下指令(前提是我已经放了这样的字符串在这个目录下的某些文件)

user@PalinUbuntu:~/Android/frameworks/base/core/jni$ find ./ -name "*" | grep -i "*LOGD*"
user@PalinUbuntu:~/Android/frameworks/base/core/jni$ 
这显然不对。

分析:

按照之前的结论,find当前路径下的所有文件,然后将这个目录下的文件的所有文件都以new line的方式标准输出,把这个输出的结果作为参数传给grep的时候,grep的路径参数接受前面的结果,但是前面的结果是以一连串以new line结束的字符串,这个文件名让grep是找不到对应文件的,所以很快返回null。

修正:

user@PalinUbuntu:~/Android/frameworks/base/core/jni$ find ./ -name "*" | xargs grep -i "*LOGD*"
user@PalinUbuntu:~/Android/frameworks/base/core/jni$ 

理由:

xargs reads items from the standard input, delimited by blanks (which can be protected  with double  or single quotes or a backslash) or newlines, and executes the command (default is /bin/echo) one or more times with any initial-arguments followed by items read from standard input.  Blank lines on the standard input are ignored.



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值