随笔分类 -  Shell

Shell 笔记
摘要:由于都是平时学习的时候积累的一些detail的点,所有很碎,很杂,没什么条理。但是都是经常会用到的,或者是不容易记住的,个人感觉还是很有用。一直记在Evernote里,现在贴在这里,但愿有一条半条的对您有用。:)!$ - the last string in the last command.$? - the return value of last commanALT+./ESC+. - the parameters in the last command^old^new - replace the 'old' with 'new' in last comma 阅读全文

posted @ 2013-09-09 23:19 name2579 阅读(1091) 评论(0) 推荐(0) 编辑

sed中关于pattern space和hold space的小实例一则
摘要:今天在看园子里的sed文章,了解到pattern space和hold space. 但是看到逆序输出文件内容的例子时有些卡壳了。虽然了解之后觉得很简单,但是对我等菜鸟来说还是需要揣摩揣摩的。说到底还是不能用Unix的方式来思考和看待问题,还需努力。sed的用法是: sed OPTIONS... [SCRIPT] [FILE...]简单说下sed的工作流程。pattern space和hold space默认都是空的。sed读入一行内容,删除尾部的换行符,存入pattern space, 然后执行SCRIPT,如果OPTIONS里没有 -n, pattern space里的内容会被输出到std 阅读全文

posted @ 2013-02-21 21:17 name2579 阅读(2505) 评论(2) 推荐(1) 编辑

Output in Linux Console
摘要:1. echoi=3;j=5;let sum=i+j;echo "sum = $sum";echo can set the text attributes and color:echo -e "\e[1;31m This is the red text \e[0m; usage:echo -e "\e[attribute_code;text_color_code;background_color_codem text_content \e[0m" attribute_code: 00-none 01-bold 04-underscore 05- 阅读全文

posted @ 2013-02-17 13:34 name2579 阅读(347) 评论(0) 推荐(0) 编辑

Arithmetic in Linux Shell (Linux Shell中的数学运算)
摘要:The caculation of Integer: 1. leti=3;j=5;let sum=i+j;let sum++;echo $sum; 2. $(())sum=$((i+j)); 3. $[]sum=$[i+j]; 4. exprsum1=`expr i+j`sum2=$(expr $i+10)The caculation of Float: 1. bc result=`echo "scale=2; 2/3" | bc`;echo $result; 阅读全文

posted @ 2013-02-17 11:22 name2579 阅读(570) 评论(0) 推荐(0) 编辑

Get the file name and extension in Shell
摘要:file="class.cpp"name=${file%.*}ext=${file#*.}echo "name=$name, ext=$ext"Output:name=class, ext=cppif file="/proj/class.cpp", name will be "/proj/class".% - means to delete the matched pattern from right to left, it is non-greedy, %% is greedy;# - means to dele 阅读全文

posted @ 2013-01-28 17:17 name2579 阅读(567) 评论(0) 推荐(0) 编辑

Newline doesn't work in Sed on Mac OS X
摘要:'\n' in the replace pattern in sed command doesn't work in Mac OS X.On Debian, we can get bellowing result:root# echo abc | sed 's/[^\n]/&\n/g'abcroot# But on Mac, it goes like this:user$ echo abc | sed 's/[^\n]/&\n/g'anbncnuser$Solution is to add \'$' bef 阅读全文

posted @ 2013-01-28 16:02 name2579 阅读(252) 评论(0) 推荐(0) 编辑

Bash递归函数计算斐波纳吉(fibonacci)数列
摘要:bash的函数,不知道还是否有其他取得返回值的方法,这里用了$? - 上一条指令的返回值$@ - 所有传入参数, 不加引号时与$*相同。加引号后"$@"="$1" "$2" ... 而 "$*"="$1 $2 ...", $@比$*用的时候多$1 - 第一个传入参数fibonacci.sh : 1 #!/bin/bash 2 3 function fibonacci 4 { 5 if [ "$@" == "1" ]; then 6 return 1; 7 阅读全文

posted @ 2013-01-16 19:45 name2579 阅读(623) 评论(0) 推荐(0) 编辑

Linux上修改命令行提示符后,超长的命令自动折叠覆盖
摘要:心血来潮给命令行提示符上了色.vi ~/.bashrcPS1="\e[32m\w \e[33m'\t' \e[36m\$ \e[0m"之后在输入长的命令时,一行显示不下之后,光标跳到当前行的开头,覆盖之前的文本,总之很乱。解决方法,给颜色设置加括号PS1="\[\e[32m\]\w \[\e[33m\]'\t' \[\e[36m\]\$ \[\e[0m\]" 还没研究是为什么??? 阅读全文

posted @ 2013-01-10 00:26 name2579 阅读(653) 评论(0) 推荐(0) 编辑

Shell 里的条件表达式
摘要:shell为GNU bash 3.2.48我想要求用户输入数字5或者6作为参数,本人参考的是鸟哥的入门课程,里面没有(目前为止)提及条件的结合,所以做过多种错误尝试: 1 # incorrect ones 2 #while [ -z "$input" || ( ! "$input" == "5" && ! "$input" == "6" ) ] 3 #while [ -z "$input" || \( ! "$input" == " 阅读全文

posted @ 2012-10-19 15:58 name2579 阅读(566) 评论(0) 推荐(0) 编辑

导航