In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "what are the csh script grammars". In daily operation, I believe many people have doubts about what csh script syntax problems there are. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "what csh script syntax there are"! Next, please follow the editor to study!
Csh instance reference:
The code is as follows:
#! / 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 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
@ nmuri-
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
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.