麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 開發 > Linux Shell > 正文

csh腳本語法實例

2020-07-27 19:12:33
字體:
來源:轉載
供稿:網友

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 49vv看片免费 | 久久久久亚洲美女啪啪 | 欧洲成人一区二区 | xnxx 美女19| 亚洲伊人色欲综合网 | 少妇一级淫片高潮流水电影 | 国产精品高潮99久久久久久久 | 精品人伦一区二区三区蜜桃网站 | 黄色99视频 | av资源在线天堂 | 国产成人精品免费视频大全最热 | 久久国产精品小视频 | 一区二区三区日韩电影 | 99激情视频| 国产91小视频在线观看 | 欧美精品成人一区二区三区四区 | 中午字幕无线码一区2020 | 久草在线新时代视觉 | 国产精品久久二区 | 最新午夜综合福利视频 | av在线一区二区三区四区 | 蜜桃麻豆视频 | 色av成人天堂桃色av | 久久久电影电视剧免费看 | 午夜色视频在线观看 | 超碰在线97国产 | 欧美黄成人免费网站大全 | 欧美日韩免费在线观看视频 | 一级黄色影片在线观看 | 亚洲va国产va | 在线a毛片免费视频观看 | 久久影院免费观看 | 国产女厕一区二区三区在线视 | 成人做爽爽爽爽免费国产软件 | 制服丝袜日日夜夜 | 一级空姐毛片 | 国产一级αv片免费观看 | 国产激情精品一区二区三区 | 国产一级爱c视频 | av电影网站在线观看 | 妇女毛片 |