
shell 编程
aclay
成事不在于力量的大小,而在于能坚持多久!
展开
-
Shell Scripting Cookbook1
who | wc -wclwc -l nusersecho "welcome to Bash"echo welecho 'asd'echo 'asd!'printf "Hello World"printf "Hello World\n"echo -e "1\t2\t3" output 1 2 3echo"1\t2\t3" output原创 2012-11-20 16:22:24 · 465 阅读 · 0 评论 -
shell 【调试脚本程序】
set -o xtraceset +o xtracetrap 'echo Exiting : critical variable = $critical variable' EXIT原创 2012-12-09 13:00:14 · 433 阅读 · 0 评论 -
shell [ here 文档的用法初步 ]
#!/bin/bashcat << !HER!hellothis is a heredocument!HER!62.txtthis is line 1this is line 2this is line 3this is line 462.sh#!/bin/bashed 62.txt << !HER!3d.,\$s/is/was/wq!HER!exit原创 2012-12-09 12:53:23 · 509 阅读 · 0 评论 -
shell [ 命令的执行 算术扩展 / 参数扩展 / 参数处理 初步用法]
1, 算术扩展#!/bin/bashx=0while [ "$x" -ne 10 ]; do echo $x x=$(($x+1))doneexit 02, 参数扩展#!/bin/bashfor i in 1 2 ; do mkdir ${i}_tmpdoneexit 03, 参数的处理#!/bin/bashunset fooecho ${foo:-bar}原创 2012-12-09 10:24:14 · 651 阅读 · 0 评论 -
shell [ find / grep 的基本使用 ]
find . -newer han2.sh -print | wc -lfind . -newer han2.sh -type f -print | wc -lfind . \( -name "*1*" -or -newer eval.sh \) -type f -printgrep 的初步使用 grep 是 通用正则表达式解析器grep in words.txtin原创 2012-12-09 08:56:09 · 793 阅读 · 0 评论 -
shell [ printf / set / shift 用法初见]
hp@ubuntu:~/shel$ printf "%s %d\t%s" "Hi world" 15 personHi world 15 person#!/bin/bashecho the date is $(date)set $(date)echo The month is $2exit 0#!/bin/bash#filename = shift1.shwhile [ "$1"原创 2012-12-08 16:02:57 · 793 阅读 · 0 评论 -
shel [ exec / exit / export ]
#!/bin/bashfoo="The first!"export bar="The second!"./export2.sh#!/bin/bashecho "$foo"echo "$bar"原创 2012-12-08 15:44:13 · 514 阅读 · 0 评论 -
shell [ eval 允许你对参数进行求值 ]
#!/bin/bashfoo=10x=fooeval y='$'$xecho $y#!/bin/bashfoo=10x=fooy='$'$xecho $y原创 2012-12-08 15:28:34 · 421 阅读 · 0 评论 -
shell [ 函数的一些用法 continue, 点. ]
#!/bin/bashi="glo"foo() { local i="loc" echo "Fun haha hhehe" echo $i}echo $ifooecho $iexit 0#!/bin/bashrm -rf fred*echo > fred1echo > fred2mkdir fred3echo > fred4for i in f原创 2012-12-08 15:14:08 · 2556 阅读 · 0 评论 -
shell Learning [ until 的用法]
#!/bin/bashrm -f file2until [ -f file2 ] && echo "hello"do touch file2 echo "Hi"doneexit 0原创 2012-12-06 19:29:10 · 539 阅读 · 0 评论 -
shell learning [and 的用法]
#!/bin/bashtouch file1rm -f file2if [ -f file1 ] && echo "hello" && [ -f file2 ] && echo "there" then echo "in if"else echo "in else"fiexit 0原创 2012-12-06 17:01:46 · 581 阅读 · 0 评论 -
shell Learning [while的初步用法]
#!/bin/bashecho "Enter password"read iwhile [ "$i" != "secret" ]; do echo "Sorry" read idoneexit 0原创 2012-12-06 17:27:17 · 655 阅读 · 0 评论 -
shell Learning [for 的用法]
#!/bin/bashfor i in bar fud 43do echo "$i"doneexit 0#!/bin/bashfor i in $(ls *.sh);do echo "$i"doneexit 0原创 2012-12-06 17:25:12 · 435 阅读 · 0 评论 -
shell Learning [or 的用法]
#!/bin/bashrm -f file1if [ -f file1 ] || echo "hello" || echo "there" then echo "in if"else echo "in else"fiexit 0原创 2012-12-06 17:00:49 · 611 阅读 · 0 评论 -
shell Learning [if elif else 的用法]
#!/bin/bashecho "Is it morning ?"read iif [ "$i" = "yes" ] then echo "Good morning!"elif [ "$i" = "no" ] then echo "Good afternoon"else echo "sorry ???" exit 1fi原创 2012-12-06 17:11:50 · 588 阅读 · 0 评论 -
shell Learning [case 的基本用法]
#!/bin/shecho "Is it morning? Please answer yes or no"read timeofdaycase "$timeofday" in yes) echo "Good morning";; no) echo "Good afternoon";; *) echo "Sorry, recognized";;esacexit 0原创 2012-12-06 10:31:56 · 470 阅读 · 0 评论 -
shell Learning [case3 执行多条语句]
#!/bin/bashecho "Is it morning?"read icase "$i" in yes | Y ) echo "Good morning!";; [nN]* ) echo "Good afternoon!";; * ) echo "sorry! recongized!" exit 1 ;;esac原创 2012-12-06 10:53:08 · 1081 阅读 · 0 评论 -
shell Learning [case 的合并匹配模式]
#!/bin/shecho "Is it morning?"read icase "$i" in yes | Y | Yes | YES ) echo "Good morning!";; n* | N* ) echo "Good Afternoon!";; * ) echo "Sorry!";;esacexit 0原创 2012-12-06 10:45:23 · 835 阅读 · 0 评论 -
shell [ trap / unset 的用法]
trap 的初步应用#!/bin/bashtrap 'rm -f fred1' INTtouch fred1echo "Print Ctrl + C "while [ -f fred1 ]; do echo "File exist!" sleep 1doneecho "the file no longer exists"trap INTecho create file原创 2012-12-08 17:56:51 · 662 阅读 · 0 评论