C-shell的例子

set filetitle = ftitle 

主要部份为

 

sed 

部份

 

s/^ *// 

表示将该行第一个字元前的空白删除

 

echo "" > $ftitle 

 

将刚刚那一行,再插回去

 

head -1 $file > ${file}head 

sed 1d $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 "$file ok" 

end 

 

-------------------------------------------------------------------- 

12. 

一个实际建立一个

 

ftp server 

的程式

 

 

 

里面包括许多应用,相当有参考价值

 

 

未完成

 

 

set path = ( /usr/bin /usr/sbin ) 

set true = `grep -c ftp /etc/passwd` 

if ( $true == 0 ) then 

echo "no ftp user in your system" 

echo -n "do you want to create the ftp user? " 

set answer = $< 

if ($answer == 'y' || $answer == 'Y') then 

set maxid = `sort /etc/passwd | tail -1 | cut -d: -f3` 

echo $maxid 

set newid = `expr $maxid + 1` 

echo $newid 

echo "/usr/sbin/useradd -d /home1

/ftp -u $newid -s /etc/false ftp" 

endif 

else 

echo "Good. Your system already has the ftp user. " 

set ftphome = `grep ftp: /etc/passwd | cut -d: -f6` 

echo $ftphome 

endif 

 

if ( -z $ftphome ) then 

echo "ftphome must be non-null" 

exit 2 

endif 

 

 

if ( $ftphome == "/usr" || $ftphome == "/" ) then 

echo "ftphome can't be / or /usr"

 

exit 2 

endif 

 

# create the ftp home directory 

if ( ! -d $ftphome ) then 

echo "mkdir $ftphome" 

endif 

 

echo "Setting up the ftphome for SunOS `uname -r`" 

 

if ( ! -d $ftphome ) then 

echo "mkdir -p $ftphome/usr/bin" 

endif 

 

cp /bin/ls $ftphome/usr/bin 

 

chmod 111 $ftphome/usr/bin/ls 

chown root $ftphome/usr/bin 

chmod 555 $ftphome/usr/bin 

 

if ( -r $ftphome/bin ) then 

mv -f $ftphome/bin $ftphome/Obin 

endif 

ln -s usr/bin $ftphome 

 

 

-------------------------------------------------------------------- 

13. 

取得该使用者的

 

UID 

 

if ( $#argv == 0 ) then 

echo "$0 usage: $1 username" 

exit 2 

endif 

 

set uid = `grep $1 /etc/passwd | cut -d: -f3` 

echo $uid 

 

 

-------------------------------------------------------------------- 

14. 

将指定档案内的

 

html 

取代成

 

htm 

 

foreach file ( *.html ) 

echo "Processing $file ..." 

sed s/html/htm/ $file > ${file}1 

cp ${file}1 $file 

rm ${file}1 

end 

 

 

-------------------------------------------------------------------- 

15. 

一个简简单单的范例,看看就好

 

 

#!/bin/csh -f 

echo ................. 

echo WELCOME to \* TAPE COPY \* 

echo ................. 

echo Enter your name: 

# $< can read from stand input 

set name = $< 

echo " " 

echo Hi $name \! 

set D = `date` 

echo Today\'s date is $D[1] $D[2] $D[3] 

if ($D[1] == Mon) then 

echo ------------------------------------------------------------- 

echo Today is $D[1]day $name, it\'s time to copy your directorys\! 

echo ------------------------------------------------------------- 

else 

echo ------------------------------------------------------------- 

echo Today is $D[1]day $name, no tape copies today\! 

echo ------------------------------------------------------------- 

endif 

 

 

-------------------------------------------------------------------- 

16. 

一个

 

finger 

的程式

 

 

set FINGER = "/usr/ucb/finger" 

 

if ( -x $FINGER ) then 

if ( $#argv == 0 ) then 

cat << TAG 

--------------------------------- 

Hahahah .... 

 

--------------------------------- 

TAG 

else 

$FINGER "$*" 

endif 

 

else 

echo "Cannot find finger on this system." 

endif 

 

 

-------------------------------------------------------------------- 

17. 

取得变数的方法

 

 

set W = `who -r` 

echo $W[9] 

 

 

 

 

-------------------------------------------------------------------- 

18. 

更改档案名称,将

 

*.html --> *.htm 

 

# rename *.html to *.htm 

echo -n "This will change *.html to *.htm. Can I continue ? (y/n) : " 

set input = $< 

if ( $input != "y" && $input != "Y" ) then 

echo "Ok. Quit..." 

exit 2 

endif 

 

foreach file ( *.html ) 

echo "Processing $file to `basename $file .html`.htm " 

mv $file `basename $file .html`.htm 

end 

 

-------------------------------------------------------------------- 

19. 

更改档案名称,将

 

*.htm --> *.html 

 

echo -n "This will change *.htm to *.html. Can I continue ? (y/n) : " 

set input = $< 

if ( $input != "y" && $input != "Y" ) then 

echo "Ok. Quit..." 

exit 2 

endif 

 

# rename *.htm to *.html 

foreach file ( *.htm ) 

echo "Processing $file to `basename $file .htm`.html " 

mv $file `basename $file .htm`.html 

end 

 

-------------------------------------------------------------------- 

20. 

将大写的档名改成小写的档名

 

tr string1 string2 

会将

 

standard input 

的字串,

 

所对应到的

 

string1, 

都以

 

string2 

取代

 

 

foreach file ( * ) 

mv $file `echo $file | tr '[A-Z]' '[a-z]'` 

end 

 

-------------------------------------------------------------------- 

21. 

将小写的档名改成大写的档名

 

 

foreach file (*) 

mv $file `echo $file | tr '[a-z]' '[A-Z]'` 

end 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值