In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Today, I would like to talk to you about what shell grammar is, many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something from this article.
Variable rz= "hufei" # defines static variable date= `date` # assignment, dynamic variable echo $rz # hufeiecho'$rz' #'$rz' cannot use echo "$rz" # hufeiecho "'$rz'" # 'hufei'echo' "$rz" #'$rz' cannot use echo `$ rz` # report error echo $dateecho ${rz} addword # variable concatenation summary: string with double quotes Variable references do not pass the parameter #! / bin/bash # in single quotation marks. This line is not necessarily the file name of echo "execution: $0" in production. Echo "first parameter is: $1"; echo "second parameter is: $2"; echo "third parameter is: $3"; echo "number: $#" # parameter number echo "pass parameter as one character: $*" # spell all parameters into a string echo "PID: $" # shell process pid to prevent error kill./test.sh 1 2 3 debugging
Add-x or #! / bin/bash-x to execute
Array arr= (hello world jike make you) echo ${arr} # defaults to the first echo ${arr [*]} #, separated by spaces echo ${arr [4]} # fourth echo ${# arr [*]} # Array number
Mode 1
If condition1then command1elif condition2 then command2else commandNfi
Mode 2 (command form)
If [$(ps-ef | grep-c "ssh")-gt 1]; then echo "true"; fiif case a = "abc" b = "abc" clockwise stringif [$a = = $b] then echo "an equal b" else echo "a no equal b" fi# numif [$c = = $b]; then echo "c equal b"; else echo "c not equal b"; fi# determines whether dir= "/ data/" file= "/ data/file" if [!-d $dir] exists in the file Then echo "${dir} does not exist"; else echo "${dir} already exists"; fiif [!-f $file]; then echo "${file} does not exist"; else echo "${file} already exists" The fi parameter states that:-d determines whether the object exists, and determines whether the object exists for the directory-f, and determines whether the object exists for the regular file-s, and the length is not 0-nt to determine whether file1 is newer than file2 ["/ data/file1"-nt "/ data/file2"] for loop.
Mode 1
For var in item1 item2... ItemNdo command1 command2... CommandNdonefor strin 'This is a string'do echo $strdone
Mode 2
For var in item1 item2... ItemN; do command1; command2... The done;for loop gets the split string, taking, for example, s = "hello,world,hadoop,jike,ou" # method 1OLDridIFS = "$IFS" IFS= "," arr= ($s) IFS= "$OLD_IFS" for x in ${arr [*]} do echo $xdone# method 2arr2 = (${arr2 [*]}) for x in ${arr2 [*]} do echo $xdonewhile cycle while conditiondo commandcards for example, while ($int)
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.