+ -
当前位置:首页 → 问答吧 → 请问这样的Shell脚本如何写?

请问这样的Shell脚本如何写?

时间:2011-08-24

来源:互联网

最近买了一本书《实战linux shell 编程与服务器管理》,根据书中提示,从http://bash.ols3.net/DL/shell-98-v1.tgz下载包文件解压,脚本文件为BIG5编码,转为UTF8:
find shell-98-v1 -type d -exec mkdir -p utf8/{} \;
find shell-98-v1 -type f -exec iconv -f BIG5 -t UTF-8 {} -o utf8/{} \;
mv utf8/* shell-98-v1
rm -fr utf8
find . 得结果
.
./shell-98-v1
./shell-98-v1/cha
./shell-98-v1/cha/samples
./shell-98-v1/cha/samples/setpars2.sh
./shell-98-v1/cha/samples/getip2.sh
./shell-98-v1/cha/samples/getline3.sh
./shell-98-v1/cha/samples/setpars.sh
./shell-98-v1/cha/samples/getline2.sh
./shell-98-v1/cha/samples/Factor.sh
./shell-98-v1/cha/samples/shift.sh
./shell-98-v1/cha/samples/loto.sh
./shell-98-v1/cha/samples/setpars3.sh
./shell-98-v1/cha/samples/getline4.sh
./shell-98-v1/cha/samples/myfun.sh
./shell-98-v1/cha/samples/mylib1.sh
./shell-98-v1/cha/samples/appendfile.sh
./shell-98-v1/cha/samples/getline1.sh
./shell-98-v1/ch7
./shell-98-v1/ch7/samples
./shell-98-v1/ch7/samples/test99.sh
./shell-98-v1/ch7/samples/fgrep.sh
./shell-98-v1/ch7/samples/getip1.sh
./shell-98-v1/chk
./shell-98-v1/chk/samples
./shell-98-v1/chk/samples/get_loading2.sh
./shell-98-v1/chk/samples/get_hostname.sh
./shell-98-v1/chk/samples/cr_acl.sh
./shell-98-v1/chk/samples/chkvol.sh
./shell-98-v1/chk/samples/my_fichecker.sh
./shell-98-v1/chk/samples/mailto2.sh
./shell-98-v1/chk/samples/cr_iptables.sh
./shell-98-v1/chk/samples/getip1.sh
./shell-98-v1/chk/samples/chk_dir_size.sh
./shell-98-v1/chk/samples/get_swap.sh
./shell-98-v1/chk/samples/mailattach.sh
./shell-98-v1/chk/samples/get_mem.sh
./shell-98-v1/chk/samples/get_loading.sh
./shell-98-v1/chk/samples/get_disk.sh
./shell-98-v1/chk/samples/get_hd_size.sh
./shell-98-v1/chk/samples/get_disk_free.sh
./shell-98-v1/chj
./shell-98-v1/chj/samples
./shell-98-v1/chj/samples/wget.sh
./shell-98-v1/chj/samples/autoftp2.sh
./shell-98-v1/chj/samples/autoscp.sh
./shell-98-v1/chj/samples/autoftp.sh
./shell-98-v1/chj/samples/dot.netrc
./shell-98-v1/ch9
./shell-98-v1/ch9/samples
./shell-98-v1/ch9/samples/forsum.sh
./shell-98-v1/ch9/samples/break1.sh
./shell-98-v1/ch9/samples/readfile3.sh
./shell-98-v1/ch9/samples/while1.sh
./shell-98-v1/ch9/samples/checkhost.sh
./shell-98-v1/ch9/samples/break2.sh
./shell-98-v1/ch9/samples/checkstr-notgood.sh
./shell-98-v1/ch9/samples/cvsfile
./shell-98-v1/ch9/samples/getcvs.sh
./shell-98-v1/ch9/samples/select2.sh
./shell-98-v1/ch9/samples/readfile2.sh
./shell-98-v1/ch9/samples/until.sh
./shell-98-v1/ch9/samples/dudir.sh
./shell-98-v1/ch9/samples/case2.sh
./shell-98-v1/ch9/samples/checkopts.sh
./shell-98-v1/ch9/samples/31r-3.sh
./shell-98-v1/ch9/samples/getdir.sh
./shell-98-v1/ch9/samples/case.sh
./shell-98-v1/ch9/samples/select.sh
./shell-98-v1/ch9/samples/continue1.sh
./shell-98-v1/ch9/samples/31r.sh
./shell-98-v1/ch9/samples/checkstr.sh
./shell-98-v1/ch9/samples/checkroot.sh
./shell-98-v1/ch9/samples/for-c.sh
./shell-98-v1/ch9/samples/prime.sh
./shell-98-v1/ch9/samples/checkint.sh
./shell-98-v1/ch9/samples/31r-2.sh
./shell-98-v1/ch9/samples/readfile.sh
./shell-98-v1/ch9/samples/checkstr2.sh
./shell-98-v1/che
./shell-98-v1/che/samples
./shell-98-v1/che/samples/sleep2.sh
./shell-98-v1/chc
./shell-98-v1/chc/samples
./shell-98-v1/chc/samples/getpid1.sh
./shell-98-v1/chc/samples/sleep.sh
./shell-98-v1/ch4
./shell-98-v1/ch4/samples
./shell-98-v1/ch4/samples/test.sh
./shell-98-v1/chd
./shell-98-v1/chd/samples
./shell-98-v1/chd/samples/dataf6.csv
./shell-98-v1/chd/samples/anonyftp.sh
./shell-98-v1/chd/samples/anonyftp1.sh
./shell-98-v1/chd/samples/dataf1
./shell-98-v1/chd/samples/chcsv24.sh
./shell-98-v1/chd/samples/dataf5
./shell-98-v1/chd/samples/dataf3
./shell-98-v1/chd/samples/vsftpd.conf
./shell-98-v1/ch8
./shell-98-v1/ch8/samples
./shell-98-v1/ch8/samples/netmask_2_bits.sh
./shell-98-v1/chg
./shell-98-v1/chg/samples
./shell-98-v1/chg/samples/inputbox1.sh
./shell-98-v1/chg/samples/radiolist2.sh
./shell-98-v1/chg/samples/menu1.sh
./shell-98-v1/chg/samples/progress1.sh
./shell-98-v1/chg/samples/yesnobox1.sh
./shell-98-v1/chg/samples/radiolist1.sh
./shell-98-v1/chg/samples/msgbox1.sh
./shell-98-v1/chg/samples/passwordbox2.sh
./shell-98-v1/chg/samples/checklist3.sh
./shell-98-v1/chg/samples/progress2.sh
./shell-98-v1/chg/samples/inputbox4.sh
./shell-98-v1/chg/samples/inputbox2.sh
./shell-98-v1/chg/samples/inputbox3.sh
./shell-98-v1/chg/samples/passwordbox1.sh
./shell-98-v1/chg/samples/checklist1.sh
./shell-98-v1/chg/samples/checklist2.sh
./shell-98-v1/ch6
./shell-98-v1/ch6/samples
./shell-98-v1/ch6/samples/heredoc.sh
./shell-98-v1/ch6/samples/lamp.sh
./shell-98-v1/ch6/samples/mustpreset2.sh
./shell-98-v1/ch6/samples/lamp2.sh
./shell-98-v1/ch6/samples/mustpreset.sh
./shell-98-v1/ch6/samples/create_prg.sh
./shell-98-v1/readme.html
./shell-98-v1/chl
./shell-98-v1/chl/samples
./shell-98-v1/chl/samples/wmultif.sh
./shell-98-v1/chl/samples/bk2.sh
./shell-98-v1/chl/samples/bk.sh
./shell-98-v1/chl/samples/mt-tape-funs.sh
./shell-98-v1/chl/samples/gen_rsync.sh
./shell-98-v1/ch5
./shell-98-v1/ch5/samples
./shell-98-v1/ch5/samples/lamp.sh
./shell-98-v1/ch5/samples/test.tgz
./shell-98-v1/ch5/samples/email.lst
./shell-98-v1/ch5/samples/dataf2
./shell-98-v1/ch5/samples/dirNAME.sh
./shell-98-v1/ch5/samples/dataf4
./shell-98-v1/ch5/samples/baseNAME.sh
./shell-98-v1/ch5/samples/dataf1
./shell-98-v1/ch5/samples/dataf5
./shell-98-v1/ch5/samples/dataf3
./shell-98-v1/ch5/samples/backupDIR.sh
./shell-98-v1/chh
./shell-98-v1/chh/samples
./shell-98-v1/chh/samples/readcfg.sh
./shell-98-v1/chh/samples/sapp.conf
./shell-98-v1/chh/samples/mksock.diff
./shell-98-v1/chh/samples/cp_progress.sh
./shell-98-v1/chh/samples/3.txt
./shell-98-v1/chh/samples/chkfile_fun.sh
./shell-98-v1/chh/samples/1.txt
./shell-98-v1/chh/samples/C
./shell-98-v1/chh/samples/C/mksock.c
./shell-98-v1/chh/samples/B
./shell-98-v1/chh/samples/B/mksock.c
./shell-98-v1/chh/samples/A
./shell-98-v1/chh/samples/A/mksock.c
./shell-98-v1/chh/samples/2.txt
./shell-98-v1/chh/samples/chkfile.sh
./shell-98-v1/chh/samples/listtoolong.sh
./shell-98-v1/chh/samples/qiconv.sh
./shell-98-v1/chh/samples/low2upper
./shell-98-v1/chh/samples/test_filequal
./shell-98-v1/chh/samples/mksock.c
./shell-98-v1/chh/samples/cp_progress2.sh
./shell-98-v1/chh/samples/mksock2.diff
./shell-98-v1/ch1
./shell-98-v1/ch1/samples
./shell-98-v1/ch1/samples/clearlog.sh
./shell-98-v1/ch1/samples/hello.sh
./shell-98-v1/chi
./shell-98-v1/chi/samples
./shell-98-v1/chi/samples/gen_dhcp.sh
./shell-98-v1/chi/samples/ca_by_rule.sh
./shell-98-v1/chi/samples/ca2.sh
./shell-98-v1/chi/samples/pa.sh
./shell-98-v1/chi/samples/gen_dns.sh
./shell-98-v1/chi/samples/delca.sh
./shell-98-v1/chi/samples/ca.sh
./shell-98-v1/chb
./shell-98-v1/chb/samples
./shell-98-v1/chb/samples/openf1.sh
./shell-98-v1/chb/samples/openf2.sh
./shell-98-v1/chb/samples/here1.sh
如何批量将samples目录下的脚本文件往上一目录移动,并删除samples目录? 顺便问一下,为什么书中提到的bash 4.0新增通配符**(就是两个星星)没有效? 书中说**可对比现行目录下所有的子目录和文件(以递归方式)。

作者: lam2888   发布时间: 2011-08-24

最近买了一本书《实战linux shell 编程与服务器管理》,根据书中提示,从http://bash.ols3.net/DL/shell-98-v1.tgz下载包文件解压,脚本文件为BIG5编码,转为UTF8:
find shell-98-v1 -type d -exec mkdir -p utf8/{} \;
find shell-98-v1 -type f -exec iconv -f BIG5 -t UTF-8 {} -o utf8/{} \;
mv utf8/* shell-98-v1
rm -fr utf8
find . 得结果
.
./shell-98-v1
./shell-98-v1/cha
./shell-98-v1/cha/samples
./shell-98-v1/cha/samples/setpars2.sh
./shell-98-v1/cha/samples/getip2.sh
./shell-98-v1/cha/samples/getline3.sh
./shell-98-v1/cha/samples/setpars.sh
./shell-98-v1/cha/samples/getline2.sh
./shell-98-v1/cha/samples/Factor.sh
./shell-98-v1/cha/samples/shift.sh
./shell-98-v1/cha/samples/loto.sh
./shell-98-v1/cha/samples/setpars3.sh
./shell-98-v1/cha/samples/getline4.sh
./shell-98-v1/cha/samples/myfun.sh
./shell-98-v1/cha/samples/mylib1.sh
./shell-98-v1/cha/samples/appendfile.sh
./shell-98-v1/cha/samples/getline1.sh
./shell-98-v1/ch7
./shell-98-v1/ch7/samples
./shell-98-v1/ch7/samples/test99.sh
./shell-98-v1/ch7/samples/fgrep.sh
./shell-98-v1/ch7/samples/getip1.sh
./shell-98-v1/chk
./shell-98-v1/chk/samples
./shell-98-v1/chk/samples/get_loading2.sh
./shell-98-v1/chk/samples/get_hostname.sh
./shell-98-v1/chk/samples/cr_acl.sh
./shell-98-v1/chk/samples/chkvol.sh
./shell-98-v1/chk/samples/my_fichecker.sh
./shell-98-v1/chk/samples/mailto2.sh
./shell-98-v1/chk/samples/cr_iptables.sh
./shell-98-v1/chk/samples/getip1.sh
./shell-98-v1/chk/samples/chk_dir_size.sh
./shell-98-v1/chk/samples/get_swap.sh
./shell-98-v1/chk/samples/mailattach.sh
./shell-98-v1/chk/samples/get_mem.sh
./shell-98-v1/chk/samples/get_loading.sh
./shell-98-v1/chk/samples/get_disk.sh
./shell-98-v1/chk/samples/get_hd_size.sh
./shell-98-v1/chk/samples/get_disk_free.sh
./shell-98-v1/chj
./shell-98-v1/chj/samples
./shell-98-v1/chj/samples/wget.sh
./shell-98-v1/chj/samples/autoftp2.sh
./shell-98-v1/chj/samples/autoscp.sh
./shell-98-v1/chj/samples/autoftp.sh
./shell-98-v1/chj/samples/dot.netrc
./shell-98-v1/ch9
./shell-98-v1/ch9/samples
./shell-98-v1/ch9/samples/forsum.sh
./shell-98-v1/ch9/samples/break1.sh
./shell-98-v1/ch9/samples/readfile3.sh
./shell-98-v1/ch9/samples/while1.sh
./shell-98-v1/ch9/samples/checkhost.sh
./shell-98-v1/ch9/samples/break2.sh
./shell-98-v1/ch9/samples/checkstr-notgood.sh
./shell-98-v1/ch9/samples/cvsfile
./shell-98-v1/ch9/samples/getcvs.sh
./shell-98-v1/ch9/samples/select2.sh
./shell-98-v1/ch9/samples/readfile2.sh
./shell-98-v1/ch9/samples/until.sh
./shell-98-v1/ch9/samples/dudir.sh
./shell-98-v1/ch9/samples/case2.sh
./shell-98-v1/ch9/samples/checkopts.sh
./shell-98-v1/ch9/samples/31r-3.sh
./shell-98-v1/ch9/samples/getdir.sh
./shell-98-v1/ch9/samples/case.sh
./shell-98-v1/ch9/samples/select.sh
./shell-98-v1/ch9/samples/continue1.sh
./shell-98-v1/ch9/samples/31r.sh
./shell-98-v1/ch9/samples/checkstr.sh
./shell-98-v1/ch9/samples/checkroot.sh
./shell-98-v1/ch9/samples/for-c.sh
./shell-98-v1/ch9/samples/prime.sh
./shell-98-v1/ch9/samples/checkint.sh
./shell-98-v1/ch9/samples/31r-2.sh
./shell-98-v1/ch9/samples/readfile.sh
./shell-98-v1/ch9/samples/checkstr2.sh
./shell-98-v1/che
./shell-98-v1/che/samples
./shell-98-v1/che/samples/sleep2.sh
./shell-98-v1/chc
./shell-98-v1/chc/samples
./shell-98-v1/chc/samples/getpid1.sh
./shell-98-v1/chc/samples/sleep.sh
./shell-98-v1/ch4
./shell-98-v1/ch4/samples
./shell-98-v1/ch4/samples/test.sh
./shell-98-v1/chd
./shell-98-v1/chd/samples
./shell-98-v1/chd/samples/dataf6.csv
./shell-98-v1/chd/samples/anonyftp.sh
./shell-98-v1/chd/samples/anonyftp1.sh
./shell-98-v1/chd/samples/dataf1
./shell-98-v1/chd/samples/chcsv24.sh
./shell-98-v1/chd/samples/dataf5
./shell-98-v1/chd/samples/dataf3
./shell-98-v1/chd/samples/vsftpd.conf
./shell-98-v1/ch8
./shell-98-v1/ch8/samples
./shell-98-v1/ch8/samples/netmask_2_bits.sh
./shell-98-v1/chg
./shell-98-v1/chg/samples
./shell-98-v1/chg/samples/inputbox1.sh
./shell-98-v1/chg/samples/radiolist2.sh
./shell-98-v1/chg/samples/menu1.sh
./shell-98-v1/chg/samples/progress1.sh
./shell-98-v1/chg/samples/yesnobox1.sh
./shell-98-v1/chg/samples/radiolist1.sh
./shell-98-v1/chg/samples/msgbox1.sh
./shell-98-v1/chg/samples/passwordbox2.sh
./shell-98-v1/chg/samples/checklist3.sh
./shell-98-v1/chg/samples/progress2.sh
./shell-98-v1/chg/samples/inputbox4.sh
./shell-98-v1/chg/samples/inputbox2.sh
./shell-98-v1/chg/samples/inputbox3.sh
./shell-98-v1/chg/samples/passwordbox1.sh
./shell-98-v1/chg/samples/checklist1.sh
./shell-98-v1/chg/samples/checklist2.sh
./shell-98-v1/ch6
./shell-98-v1/ch6/samples
./shell-98-v1/ch6/samples/heredoc.sh
./shell-98-v1/ch6/samples/lamp.sh
./shell-98-v1/ch6/samples/mustpreset2.sh
./shell-98-v1/ch6/samples/lamp2.sh
./shell-98-v1/ch6/samples/mustpreset.sh
./shell-98-v1/ch6/samples/create_prg.sh
./shell-98-v1/readme.html
./shell-98-v1/chl
./shell-98-v1/chl/samples
./shell-98-v1/chl/samples/wmultif.sh
./shell-98-v1/chl/samples/bk2.sh
./shell-98-v1/chl/samples/bk.sh
./shell-98-v1/chl/samples/mt-tape-funs.sh
./shell-98-v1/chl/samples/gen_rsync.sh
./shell-98-v1/ch5
./shell-98-v1/ch5/samples
./shell-98-v1/ch5/samples/lamp.sh
./shell-98-v1/ch5/samples/test.tgz
./shell-98-v1/ch5/samples/email.lst
./shell-98-v1/ch5/samples/dataf2
./shell-98-v1/ch5/samples/dirNAME.sh
./shell-98-v1/ch5/samples/dataf4
./shell-98-v1/ch5/samples/baseNAME.sh
./shell-98-v1/ch5/samples/dataf1
./shell-98-v1/ch5/samples/dataf5
./shell-98-v1/ch5/samples/dataf3
./shell-98-v1/ch5/samples/backupDIR.sh
./shell-98-v1/chh
./shell-98-v1/chh/samples
./shell-98-v1/chh/samples/readcfg.sh
./shell-98-v1/chh/samples/sapp.conf
./shell-98-v1/chh/samples/mksock.diff
./shell-98-v1/chh/samples/cp_progress.sh
./shell-98-v1/chh/samples/3.txt
./shell-98-v1/chh/samples/chkfile_fun.sh
./shell-98-v1/chh/samples/1.txt
./shell-98-v1/chh/samples/C
./shell-98-v1/chh/samples/C/mksock.c
./shell-98-v1/chh/samples/B
./shell-98-v1/chh/samples/B/mksock.c
./shell-98-v1/chh/samples/A
./shell-98-v1/chh/samples/A/mksock.c
./shell-98-v1/chh/samples/2.txt
./shell-98-v1/chh/samples/chkfile.sh
./shell-98-v1/chh/samples/listtoolong.sh
./shell-98-v1/chh/samples/qiconv.sh
./shell-98-v1/chh/samples/low2upper
./shell-98-v1/chh/samples/test_filequal
./shell-98-v1/chh/samples/mksock.c
./shell-98-v1/chh/samples/cp_progress2.sh
./shell-98-v1/chh/samples/mksock2.diff
./shell-98-v1/ch1
./shell-98-v1/ch1/samples
./shell-98-v1/ch1/samples/clearlog.sh
./shell-98-v1/ch1/samples/hello.sh
./shell-98-v1/chi
./shell-98-v1/chi/samples
./shell-98-v1/chi/samples/gen_dhcp.sh
./shell-98-v1/chi/samples/ca_by_rule.sh
./shell-98-v1/chi/samples/ca2.sh
./shell-98-v1/chi/samples/pa.sh
./shell-98-v1/chi/samples/gen_dns.sh
./shell-98-v1/chi/samples/delca.sh
./shell-98-v1/chi/samples/ca.sh
./shell-98-v1/chb
./shell-98-v1/chb/samples
./shell-98-v1/chb/samples/openf1.sh
./shell-98-v1/chb/samples/openf2.sh
./shell-98-v1/chb/samples/here1.sh
如何批量将samples目录下的脚本文件往上一目录移动,并删除samples目录? 顺便问一下,为什么书中提到的bash 4.0新增通配符**(就是两个星星)没有效? 书中说**可对比现行目录下所有的子目录和文件(以递归方式)。

作者: lam2888   发布时间: 2011-08-24