摘要: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
阅读全文
摘要:'\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
阅读全文
摘要:bash的函数,不知道还是否有其他取得返回值的方法,这里用了$? - 上一条指令的返回值$@ - 所有传入参数, 不加引号时与$*相同。加引号后"$@"="$1" "$2" ... 而 "$*"="$1 $2 ...", $@比$*用的时候多$1 - 第一个传入参数fibonacci.sh : 1 #!/bin/bash 2 3 function fibonacci 4 { 5 if [ "$@" == "1" ]; then 6 return 1; 7
阅读全文
摘要:心血来潮给命令行提示符上了色.vi ~/.bashrcPS1="\e[32m\w \e[33m'\t' \e[36m\$ \e[0m"之后在输入长的命令时,一行显示不下之后,光标跳到当前行的开头,覆盖之前的文本,总之很乱。解决方法,给颜色设置加括号PS1="\[\e[32m\]\w \[\e[33m\]'\t' \[\e[36m\]\$ \[\e[0m\]" 还没研究是为什么???
阅读全文