admin 管理员组文章数量: 1086019
2024年4月28日发(作者:忙怎么组词二年级上册)
Genesis2000脚本命令大全
的用法,注意每一个case必须要以breaksw结尾
否则会继续执行下一个case的命令
(1)另外,$<的意思是取得使用者的standinput
(2)echo若加上-n的选项,则游标会停留在该行最后
echo-n"Inputonecolor:
setSTOPLIGHT=$<
switch($STOPLIGHT)
casered:
echo"red"
breaksw
caseorange:
echo"orange"
breaksw
casegreen:
echo"green"
breaksw
default:
"
echo"youinput$STOPLIGHT"
endsw
--------------------------------------------------------------------
2.利用set来取得变数,setABC="IamABC"
也可以利用`command`来取得命令
且外,case也可以用万用字元*来代替
setVER=`uname-r`
switch($VER)
case5.5:
echo"runthesetupof$VER"
breaksw
case5.3:
echo"runthesetupof$VER"
breaksw
case5.*:
echo"like5.x"
breaksw
case4.*:
echo"like4.x"
breaksw
default:
echo"noidea"
endsw
--------------------------------------------------------------------
的语法,比较数字
setn1=1
setn2=2
if($n1==$n2)then
echo"$n1Equal$n2"
else
echo"$n1NotEqual$n2"
endif
--------------------------------------------------------------------
的语法,比较字串
setn1=abcdef
setn2=abcde
if($n1==$n2)then
echo"$n1Equal$n2"
else
echo"$n1NotEqual$n2"
endif
--------------------------------------------------------------------
的语法,比较相似的字串
setn1=abcdef
setn2=abcde
if($n1=~$n2)then
echo"$n1Like$n2"
else
echo"$n1NotLike$n2"
endif
--------------------------------------------------------------------
的语法,比较数字的大小
setn1=1
setn2=2
if($n1>$n2)then
echo"$n1>$n2"
else
echo"$n1<$n2"
endif
--------------------------------------------------------------------
7.每分钟执行一次的程式
#mm等于当天时间的【分钟】数
setmm=`date|cut-d''-f4|cut-d:-f2`
if(-r$)then
rm$
touch$
else
touch$
endif
while($mm<=16)
setmm=`date|cut-d''-f4|cut-d:-f2`
echo"$mmnowis`date`"
sleep60
#echo"$mmnowis`date`">>$
end
echo"Over">>$
--------------------------------------------------------------------
8.一个回圈的范例,并且利用expr去作加的动作
回圈的语法如下:
foreachnumber(123)
echo$number
end
setcounter=0
while($counter<=10)
echo"sleepingfor5seconds"
sleep5
counter=`expr$counter+1`
end
--------------------------------------------------------------------
9.设定一个用当天月份与日期作为档案名称的程式
如今天是10/02,则$prefix会等于该程式+1002
1002
setprefix=`basename$0``date'+%m%d'`
echo$0
echo$prefix
--------------------------------------------------------------------
10.移除在foreach回圈内指定的档案内的font字串
foreachfile([b,e,g,h,s]*.html)
echo-n"Processing$file,removethelinenumber`grep-nfont
$file`"
#$log表示这个$file有几个font字串
setlog=`grep-cfont$file`
if($log=='0')then
echo",pass$file"
else
#先找出该档案的第一次出现font的行数,如果3,则$cmd
=3d
setcmd=`grep-nfont$file|cut-d:-f1|head-1`d
#利用sed去执行删除的动作,并把结果输出到${file}1
sed$cmd$file>${file}1
#如果${file}1没有资料,则passing
if(-z${file}1)then
echo",${file}1iszero"
else
cp${file}1$file
rm{$file}1
echo",
endif
endif
end
$fileremoveok"
#后来看过sed的更进一步用法,发现先前写的太笨了,试试这个
#sed/font/d$file>${file}1
#一次OK,我真是大笨蛋
--------------------------------------------------------------------
11.功能:将指定的档案中,出现第一次【回】的那一行,加上 tle>xxxx foreachfile(sky*.html) setfiletitle=ftitle #主要部份为sed部份s/^*//表示将该行第一个字 元前的空白删除 echo"
le>">$ftitle
#将刚刚那一行,再插回去
head-1$file>${file}head
sed1d$file>${file}1
cat$ftitle>>${file}head
cat${file}1>>${file}head
cp${file}head$file
rm${file}1
rm$ftitle
rm${file}head
echo"$fileok"
end
--------------------------------------------------------------------
*//'`
12.一个实际建立一个ftpserver的程式
里面包括许多应用,相当有参考价值
(未完成)
setpath=(/usr/bin/usr/sbin)
#
settrue=`grep-cftp/etc/passwd`
if($true==0)then
echo"noftpuserinyoursystem"
echo-n"doyouwanttocreatetheftpuser?"
setanswer=$<
if($answer=='y'||$answer=='Y')then
setmaxid=`sort/etc/passwd|tail-1|cut-d:-f3`
echo$maxid
setnewid=`expr$maxid+1`
echo$newid
echo"/usr/sbin/useradd-d/home1/ftp-u$newid-s/etc/false
ftp"
endif
else
echo"stemalreadyhastheftpuser."
setftphome=`grepftp:/etc/passwd|cut-d:-f6`
echo$ftphome
endif
if(-z$ftphome)then
echo"ftphomemustbenon-null"
exit2
endif
if($ftphome=="/usr"||$ftphome=="/")then
echo"ftphomecan'tbe/or/usr"
exit2
endif
#createtheftphomedirectory
if(!-d$ftphome)then
echo"mkdir$ftphome"
endif
echo"SettinguptheftphomeforSunOS`uname-r`"
if(!-d$ftphome)then
echo"mkdir-p$ftphome/usr/bin"
endif
cp/bin/ls$ftphome/usr/bin
chmod111$ftphome/usr/bin/ls
chownroot$ftphome/usr/bin
chmod555$ftphome/usr/bin
if(-r$ftphome/bin)then
mv-f$ftphome/bin$ftphome/Obin
endif
ln-susr/bin$ftphome
--------------------------------------------------------------------
13.取得该使用者的UID
if($#argv==0)then
echo"$0usage:$1username"
exit2
endif
setuid=`grep$1/etc/passwd|cut-d:-f3`
echo$uid
--------------------------------------------------------------------
14.将指定档案内的html取代成htm
foreachfile(*.html)
echo""
seds/html/htm/$file>${file}1
cp${file}1$file
rm${file}1
end
--------------------------------------------------------------------
15.一个简简单单的范例,看看就好
#!/bin/csh-f
echoWELCOMEto*TAPECOPY*
echoEnteryourname:
#$ setname=$< echo"" echoHi$name! setD=`date` echoToday'sdateis$D[1]$D[2]$D[3] if($D[1]==Mon)then echo------------------------------------------------------------- echoTodayis$D[1]day$name,it'stimetocopyyourdirector ys! echo------------------------------------------------------------- else echo------------------------------------------------------------- echoTodayis$D[1]day$name,notapecopiestoday! echo------------------------------------------------------------- endif -------------------------------------------------------------------- 16.一个finger的程式 setFINGER="/usr/ucb/finger" if(-x$FINGER)then if($#argv==0)then cat< --------------------------------- --------------------------------- TAG else $FINGER"$*" endif else echo"Cannotfindfingeronthissystem." endif -------------------------------------------------------------------- 17.取得变数的方法 setW=`who-r` echo$W[9] -------------------------------------------------------------------- 18.更改档案名称,将*.html-->*.htm #rename*.htmlto*.htm echo-n"Thiswillchange*.htmlto*.ntinue?(y/n): " setinput=$< if($input!="y"&&$input!="Y")then echo"..." exit2 endif foreachfile(*.html) echo"Processing$fileto`basename$`.htm" mv$file`basename$`.htm end -------------------------------------------------------------------- 19.更改档案名称,将*.htm-->*.html echo-n"Thiswillchange*.htmto*.ntinue?(y/n): " setinput=$< if($input!="y"&&$input!="Y")then echo"..." exit2 endif #rename*.htmto*.html foreachfile(*.htm) echo"Processing$fileto`basename$`.html" mv$file`basename$`.html end -------------------------------------------------------------------- 20.将大写的档名改成小写的档名 trstring1string2会将standardinput的字串, 所对应到的string1,都以string2取代 foreachfile(*) mv$file`echo$file|tr'[A-Z]''[a-z]'` end -------------------------------------------------------------------- 21.将小写的档名改成大写的档名 foreachfile(*) mv$file`echo$file|tr'[a-z]''[A-Z]'` end
版权声明:本文标题:Genesis2000脚本命令大全 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/b/1714248406a671642.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论