文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

csh脚本语法实例

2022-06-04 21:44

关注

csh实例 参考:

#!/bin/csh -vx

#csh -vx show the command before running to help debug

#just to check syntax #csh -n $0

#argv if ($#argv < 2) then echo "Sorry, but you entered too few parameters" echo "usage: $0 arg1 arg2 exit endif set arg1 = $1 set arg2 = #2

foreach i ($*) echo $i end #execute commands echo "Hello there `whoami`. How are you today?" echo "You are currently using `hostname` and the time is `date`" echo "Your directory is `pwd`" whoami hostname date pwd

#var set name = Mark echo $name set name = "Mark Meyer" # if the string has space, must use "" echo $name # it means set to NULL set name = unset name # get user input set x = $< set current_user = `whoami`

#buildin vars echo $user # who am I? echo $status # a numeric variable, usually used to retun error codes

#Arithmetic variables @ i = 2 @ k = ($x - 2) * 4 @ k = $k + 1 @ i-- @ i++

#array set name = (mark sally kathy tony) echo $#name # num of the array echo $name[1] echo $name[4] echo $name[2-3] echo $name[2-] # all elements from 2 to the end echo $name[1-3] echo $name[$i] set name = ($name doran) set name = (doran $name) set name = ($name[1-2] alfie $name[3-]) shift name # get rid of the frist element of the array shift #if no argument is given, it will get rid of argv

#Expressions and operators == equal (either strings or numbers) != not equal (either strings or numbers) =~ string match !~ string mismatch <= numerical less than or equal to >= numerical greater than or equal to > numerical greater than < numerical less than

-e file file merely exists (may be protected from user) -r file file exists and is readable by user -w file file is writable by user -x file file is executable by user -o file file is owned by user -z file file has size 0 -f file file is an ordinary file -d file file is a directory

! -- negate && -- logical and || -- logical or

#if-else # run cmd as if expression if ({grep -s junk $1}) then echo "We found junk in file $1" endif # check if the var is defined if ($?dirname) then ls $dirname endif

if (-e somefile) then grep $1 somefile else echo "Grievous error! Database file does not exist". endif

#foreach foreach i (*) if (-f $i) then echo "============= $i ===================" head $i endif if (-d $i) then (cd $i; headers) endif end

#while while ($#argv > 0) grep $something $argv[1] end

@ n = 5 while ($n) # do something @ n-- end

#switch-case switch ($argv[$i]) case quit: break # leave the switch statement case list: ls breaksw case delete: case erase: @ k = $i + 1 rm $argv[$k] breaksw endsw #here document grep $i <<HERE John Doe 101 Surrey Lane London, UK 5E7 J2K Angela Langsbury 99 Knightsbridge, Apt. K4 Liverpool John Major 10 Downing Street London HERE

cat > tempdata <<ENDOFDATA 53.3 94.3 67.1 48.3 01.3 99.9 42.1 48.6 92.8 ENDOFDATA

exit 0

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     801人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     348人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     311人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     432人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     220人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-服务器
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯