欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

csh腳本語法實(shí)例

 更新時(shí)間:2014年11月24日 11:52:54   投稿:junjie  
這篇文章主要介紹了csh腳本語法實(shí)例,小編看起來和bash shell也差不太多,需要的朋友可以參考下

csh實(shí)例 參考:

復(fù)制代碼 代碼如下:

#!/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

相關(guān)文章

  • bash腳本中if語句的使用方法

    bash腳本中if語句的使用方法

    與大多數(shù)語言一樣,bash 有自己的條件形式。在使用時(shí),要遵循以上格式;即,將 "if" 和 "then" 放在不同行,并使 "else" 和結(jié)束處必需的 "fi" 與它們水平對(duì)齊。這將使代碼易于閱讀和調(diào)試
    2014-05-05
  • Shell實(shí)現(xiàn)字符串處理的方法詳解

    Shell實(shí)現(xiàn)字符串處理的方法詳解

    這篇文章主要為大家詳細(xì)介紹了Linux?Shell中實(shí)現(xiàn)字符串處理的方法,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,感興趣的可以了解一下
    2022-09-09
  • Shell中實(shí)現(xiàn)飛行文字效果

    Shell中實(shí)現(xiàn)飛行文字效果

    這篇文章主要介紹了Shell中實(shí)現(xiàn)飛行文字效果,比較炫的一個(gè)特效,在網(wǎng)頁中比較常見,需要的朋友可以參考下
    2014-06-06
  • Shell內(nèi)置命令之exit的語法與實(shí)例

    Shell內(nèi)置命令之exit的語法與實(shí)例

    系統(tǒng)中是有exit命令的,用于退出當(dāng)前用戶的登錄狀態(tài),但是在?Shell?腳本中,exit?語句是用來退出當(dāng)前腳本的,下面這篇文章主要給大家介紹了關(guān)于Shell內(nèi)置命令之exit的語法與實(shí)例,需要的朋友可以參考下
    2022-03-03
  • Shell腳本實(shí)現(xiàn)根據(jù)文件的修改時(shí)間來分類文件

    Shell腳本實(shí)現(xiàn)根據(jù)文件的修改時(shí)間來分類文件

    這篇文章主要介紹了Shell腳本實(shí)現(xiàn)根據(jù)文件的修改時(shí)間來分類文件,本文直接給出實(shí)現(xiàn)代碼,需要的朋友可以參考下
    2015-07-07
  • Linux nano命令使用示例

    Linux nano命令使用示例

    nano是一個(gè)小型、免費(fèi)、友好的編輯器,旨在取代非免費(fèi)Pine包中的默認(rèn)編輯器Pico,nano是一個(gè)字符終端的文本編輯器,有點(diǎn)像DOS下的editor程序,這篇文章主要介紹了Linux nano命令使用示例,需要的朋友可以參考下
    2023-03-03
  • shell腳本學(xué)習(xí)指南[五](Arnold Robbins & Nelson H.F. Beebe著)

    shell腳本學(xué)習(xí)指南[五](Arnold Robbins & Nelson H.F. Beebe著)

    這篇文章主要介紹了shell腳本學(xué)習(xí)指南[五](Arnold Robbins & Nelson H.F. Beebe著),需要的朋友可以參考下
    2014-02-02
  • shell腳本實(shí)現(xiàn)多彩進(jìn)度條

    shell腳本實(shí)現(xiàn)多彩進(jìn)度條

    這篇文章主要介紹了shell腳本實(shí)現(xiàn)多彩進(jìn)度條的相關(guān)資料,需要的朋友可以參考下
    2017-07-07
  • 處理JSON最強(qiáng)命令jq使用場景

    處理JSON最強(qiáng)命令jq使用場景

    jq命令是處理json字符串的神器,?主要用于獲取JSON屬性/簡單重組JSON字符串,本章詳細(xì)介紹jq的主要應(yīng)用場景,感興趣的朋友跟隨小編一起看看吧
    2023-07-07
  • shell腳本編程之if語句學(xué)習(xí)筆記

    shell腳本編程之if語句學(xué)習(xí)筆記

    這篇文章主要介紹了shell腳本編程之if語句學(xué)習(xí)筆記,本文先是給出了程序代碼,然后詳細(xì)的分解了第句代碼的作用,需要的朋友可以參考下
    2014-09-09

最新評(píng)論