a=(a b c);echo lang c${#a[@]}

 上传我的文档
 下载
 收藏
该文档贡献者很忙,什么也没留下。
 下载此文档
PHP试卷(A)和参考答案
下载积分:100
内容提示:PHP试卷(A)和参考答案
文档格式:PDF|
浏览次数:209|
上传日期: 11:42:08|
文档星级:
全文阅读已结束,如果下载本文需要使用
 100 积分
下载此文档
该用户还上传了这些文档
PHP试卷(A)和参考答案
关注微信公众号terrifyA.buryB.employC.styleD.county 题目和参考答案——精英家教网——
暑假天气热?在家里学北京名师课程,
& 题目详情
terrifyA.buryB.employC.styleD.county
练习册系列答案
科目:高中英语
来源:学年江苏省高三上学期期中考试英语试卷(解析版)
题型:阅读理解
Cities alarmed by deaths and injuries ofpedestrians are taking efforts to make crosswalks safer for people on foot,especially seniors and children who need more time to cross streets.A pedestrian is killed in a traffic accidentin the USA every 110 one is injured every nine minutes, according toofficial data. Crosswalks can be especially dangerous for the elderly. Amongpeople 70 and older, 36% of pedestrian deaths in 2006 occurred in crosswalks,compared&& with 21% of those younger than 70, according to theInsurance Institute for Highway Safety.The Federal Highway Administration(FHWA)advise that next year states increase by nearly 15% the amount of& timetraffic lights provide for pedestrians to cross the street after the flashingorange hand appears.FHWA spokesman Doug Hecox says reasons forthe change include an aging population that needs more time to cross,health-conscious Americans walking more, children encouraged to walk to preventgetting overweight and high gas prices pushing people to walk instead of drive.Pedestrian deaths went down by 12% from5,449 in 1996 to 4,784 in 2006, Bur among those in
were killed incrosswalks, down slightly from 488 ten years earlier, the National Highway TrafficSafety Administration(NHTSA) says.1.Which of the following is true accordingto the text?
A.Among 100 pedestrian deaths there were 21 people younger than 70
B.Old people are more likely to meet with accidents happened per hour.
C.Traffic accidents killed more old people than young people
D.About seven traffic accidents happened per hour.
2.What is FHWA’s suggestion to states?
A.Fixing more traffic lights
B.Providing more crosswalks
C.Giving pedestrians more time to cross streets.
D.Drivers don’t give way
3.What’s the cause of the crosswalk safetyproblem according to the test?
A.There’re many cars and buses on the road.
B.Pedestrians are careless.
C.Crosswalks are crowded.
D.Drivers don’t give way.
4.The report from NHTSA suggests that
A.fewer people were injured in crosswalks
B.crosswalk safety has been greatly improved
C.much has been done to reduce traffic accidents
D.pedestrian deaths in crosswalks remain a serious problem
科目:高中英语
来源:2012届江苏省苏州五中高三上学期期中考试英语试卷(带解析)
题型:阅读理解
Cities alarmed by deaths and injuries of pedestrians are taking efforts to make crosswalks safer for people on foot, especially seniors and children who need more time to cross streets.A pedestrian is killed in a traffic accident in the USA every 110 one is injured every nine minutes, according to official data. Crosswalks can be especially dangerous for the elderly. Among people 70 and older, 36% of pedestrian deaths in 2006 occurred in crosswalks, compared&& with 21% of those younger than 70, according to the Insurance Institute for Highway Safety. The Federal Highway Administration(FHWA) advise that next year states increase by nearly 15% the amount of& time traffic lights provide for pedestrians to cross the street after the flashing orange hand appears. FHWA spokesman Doug Hecox says reasons for the change include an aging population that needs more time to cross, health-conscious Americans walking more, children encouraged to walk to prevent getting overweight and high gas prices pushing people to walk instead of drive. Pedestrian deaths went down by 12% from 5,449 in 1996 to 4,784 in 2006, Bur among those in
were killed in crosswalks, down slightly from 488 ten years earlier, the National Highway Traffic Safety Administration(NHTSA) says.【小题1】Which of the following is true according to the text?A.Among 100 pedestrian deaths there were 21 people younger than 70B.Old people are more likely to meet with accidents happened per hour.C.Traffic accidents killed more old people than young peopleD.About seven traffic accidents happened per hour.【小题2】What is FHWA’s suggestion to states?A.Fixing more traffic lightsB.Providing more crosswalksC.Giving pedestrians more time to cross streets.D.Drivers don’t give way【小题3】What’s the cause of the crosswalk safety problem according to the test?A.There’re many cars and buses on the road.B.Pedestrians are careless.C.Crosswalks are crowded.D.Drivers don’t give way.【小题4】The report from NHTSA suggests thatA.fewer people were injured in crosswalksB.crosswalk safety has been greatly improvedC.much has been done to reduce traffic accidentsD.pedestrian deaths in crosswalks remain a serious problem
科目:高中英语
题型:阅读理解
People have been painting pictures for at least 30,000 years. The earliest pictures were painted by people who hun??ted animals. They used to paint pictures of the animals they wanted to catch and kill. Pictures of this kind have been found on the walls of caves in France and Spain. No one knows why they were painted there. Perhaps the painters thought that their pictures would help them to catch these animals. Or per??haps human beings have always wanted to tell stories accord??ing to pictures. About 5,000 years ago the Egyptians and other people in the Near East began to use pictures as a kind of writing. They drew simple pictures or signs to represent things and ideas, and also to represent the sounds of their language. The signs these people used became a kind of alphabet(字母表). The Egyptians used to record information and to tell sto??ries by putting picture-writing and pictures together. When an important person died, scenes and stories from his life were painted and carved on the walls of the place where he was bur??ied. Some of these pictures are like modem comic-strip sto??ries. It has been said that Egypt is the home of the comic-strip. But, for the Egyptians, pictures still had magic power. So they did not try to make their way of writing simple. The ordinary people could not understand it. & By the year 1,000 BC, people who lived in the area a-round the Mediterranean Sea had developed a simpler system of writing. The signs they used were very easy to write, and there were fewer of them than in the Egyptian system. This was because each sign, or letter, represented only one sound in their language. The Greeks developed this system and formed the letters of the Greek alphabet. The Romans copied the idea, and the Roman alphabet is now used all over the world. These days we can write down a story, or record informa??tion, without using pictures. But we still need pictures of all kinds: drawings, photographs, signs and diagrams. We find them everywhere: in books and newspapers, in the streets, and on the walls of the places where we live and work. Pic??tures help us to understand and remember things more easily, and they can make a story much more interesting. 6. Pictures of animals were painted on the walls of caves in France and Spain because ________. A. the hunters wanted to see the pictures& B. the painters were animal lovers C. the painters wanted to show imagination D. the pictures were thought to be helpful 7.The Greek alphabet was simpler than the Egyptian system for all the following reasons EXCEPT that ________. & A. the former was easy to write&&& &&&& B. there were fewer signs in the former C. the former was easy to pronounce&&& D. each sign stood for only one sound 8. Which of the following statements is TRUE? A. The Egyptian signs later became a particular alphabet. B. The Egyptians liked to write comic-strip stories. C. The Roman alphabet was developed from the Egyptian one. D. The Greeks copied their writing system from the Egyp??tians. 9. In the last paragraph, the author thinks that pictures __________. A. should be made comprehensible&&&&&& & B. should be made interesting C. are of much use in our life&&&&&& &&&&& D. are disappearing from our life
科目:高中英语
来源:江苏省扬州市2010届高三第三次调研测试
题型:阅读理解
BI am a person who does not like to wait in line. However, I realize anger will get me nowhere. Considering this, I have decided to turn my frustration(沮丧) to productive ends. In short, I am constantly hunting around for what I call “waiting in line books”, especially those that are designed for being read in snippets(文摘), so there is no extended story line to lose track of. Another requirement is that they be small enough to slip neatly into my back pocket.The other day I went to the supermarket and was surprised to see that the place was crowded with shoppers, but no worries. I parked my cart behind five others and pulled out my vocabulary builder. Within a few seconds I was totally absorbed, and rather than seething at the 15 minutes it took to advance to the cashier, I learned that nankeen is “a yellow cotton cloth”, or, in the plural, “trousers made of it”. The acquisition of new words led me into a place where I would otherwise not have enjoyed myself so much.Once, at a yard sale, I found two small pocket books titled Sidelights on American History (copyright 1919). The seller approached as I looked through the pages. “You want them?”“First I need to see if they fit,” I told him. He watched as I slipped Volume 1 into my back pocket. “Perfect. I’ll take them.”10 minutes later, I was at the carwash, where the waiting line was six vehicles long. Thank goodness for my books! By the time my car was being soaped and power sprayed, I had learned about the Annapolis Convention, the early life of Aaron Bur.The more the world demands that I wait, the more I learn from my waiting library. In fact, I have become so fond of my “waiting” books that my spirits actually rise when I see a long line I must stand in. It is most likely I would be regarded as a bookish, lonely soul. But little would they realize that I was enjoying the company of those “waiting” books. And just as Disraeli said, “Everything comes if a man will only wait”.60. When buying a book the writer _____.A. has his own rules&&&&&&&&&&&&&&&&&&&&&&& B. prefers books of small sizeC. chooses books by famous writers&&&&&&&&&&& D. has no particular appetite61. The truth behind the story is that the writer wants to tell us _____.A. reading is not only important but also practical B. one is expected to learn to adjust oneself rather than complainC. reading is the best way to kill timeD. knowledge is power and wisdom is fortune62. The underlined expression in paragraph 3 “seething at” probably means _____.A. angry at&&&&&&&&&&&&&&&&&& B. delighted at &&&&&&&&&&&& C. surprised at&&&&&&& D. excited at63. The sentence in Paragraph 2 “there is no extended story line to lose track of” shows that _____.A. what the writer reads is not difficult to understandB. the writer likes to read interesting stories while waiting in lineC. the writer can stop wherever needed with no plot to leave outD. the writer does not necessarily reach his understanding
科目:高中英语
来源:江苏省学年高三下学期高考模拟英语试题(5)
题型:阅读理解
There was once a beautiful nymph calledEcho. But E she was fond of talking, and whether in chat orargument, would have the last word. As she was good company , she and Zeusbecame good friends. However,Zeus’ wife, Hera, became jealous. She followed Zeus to the earth tofind out what he was doing and Zeus asked Echo to distract Hera until he couldescape. Later when Hera discovered she had been tricked, she became very angry.She turned on Echo and said, “You shall lose the use of your tongue because youcheated me. You’ll have the last word, bur no longer have the power to speakfirst.” So from that moment on, Beautiful Echo was hardly able to hold aconversation because she could only repeat the last words of those around her.She became very embarrassed and hid herself deep in the woods.One day a handsome young man calledNarcissus came into the woods. He had been hunting deer and lost his way.However, the moment Echo saw him, she fell in love with him. She followed him,wishing to tell him but unable o begin a conversation. Oh, how she wished shecould speak first. Unfortunately, Narcissus was far too busy worrying aboutwhere his companions might be and how he could find his way home.Eventually Narcissus, with Echo followingbehind along, came to a pool of water in the middle of the woods. Feelingthirsty, Narcissus bent down to drink. As he did so, he saw a beautifulcreature in the water staring up at him. . He immediately bent over and said tohim, “I love you!” Echo, nearby, and seeing her chance, immediately responded“…. I love you!” But it was too late. Narcissus was already in love, withhimself.`&&&&& Thestranger seemed to rise up closer to Narcissus who was so involved that heentirely failed to notice Echo. “I want to stay and look at this beautifulsight forever,” he whispered dreamily to himself.”… Forever,” repeated Echosadly. “Come her,” called Narcissus to his reflection as he moved his head andthe creature seemed to move away. “…Here.” responded Echo. Narcissus bent backdown to see his reflection more clearly. “So beautiful! I’ve never seenanything so beautiful!” “….So beautiful!” responded Echo truthfully.Narcissus remained by the water refusingall Echo’s silent offers of food and drink until he died. Where he had been, aflower grew in his place, as beautiful as Narcissus himself. As for Echo, fromthat time forward, she also didn’t eat or drink till she turned to rocks andall that was left was her voice. Even now you can still hear Echo trying toattract Narcissus’ attention by repeating his words and still see Narcissus asa beautiful flower growing near a pool.63. Why was Echo unable to& letNarcissus know she loved him?A. Because she had lost the ability tospeak.&&&&&&& B. Because she was too shy tospeak first.C. Because Hera had taken away her abilityto speak first.D.& Because Narcissus took no noticeof her.64. “The stranger” in paragraph 4 refers to______.A.Echo&&&&&&&& B. A fairy in thewoods.&&&&&&& C.Hera.&&&&&&&& D. Narcissus himself.65. Which of the following kinds of personcan be described as a “Narcissus”?A. A person who loves and admires himselfor herself.B. A person who’s afraid of being separatedfrom companions.C. A person who is too shy to have a chatwith other people.D. A person who loves to admire beautifulwater flowers.66. Which of the following is the correctorder of the events?a) Hera wouldn’t let Echo start aconversation.b) Narcissus fell in love with hisreflection in the water.c) Echo saw Narcissus and fell in love atthe first sight.d) Echo distracted Hera to help Zeusescape. e) Narcissus became a flower and Echo arock.A.a-b-c-d-e&&&&&&&&&& B.d-a-c-b-e&&&&&&&&&& C.d-a-b-c-e&&&&&&&&&& D.c-d-a-b-e67. What’s the best title of this passage?A. Echo’ssacrifice.&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&B. Echo and Hera.C. Echo andNarcissus.&&&&&&&&&&&&&&&&&&&&&&D. Narcissus’s self-love. &&&&&&
精英家教网新版app上线啦!用app只需扫描书本条形码就能找到作业,家长给孩子检查作业更省心,同学们作业对答案更方便,扫描上方二维码立刻安装!
请输入姓名
请输入手机号A-B--C喜欢的音乐 - 歌单 - 网易云音乐
A-B--C喜欢的音乐
播放:842次
网易云音乐多端下载
同步歌单,随时畅听320k好音乐
网易公司版权所有(C)杭州乐读科技有限公司运营:shell中的各种括号的使用方法
投稿:mdxy-dxy
字体:[ ] 类型:转载 时间:
这篇文章主要介绍了shell中的各种括号的使用方法,需要的朋友可以参考下
在这里我想说的是几种shell里的小括号,大括号结构和有括号的变量,命令的用法,如下:
4.${var:-string},${var:+string},${var:=string},${var:?string}
5.$((exp))
6.$(var%pattern),$(var%%pattern),$(var#pattern),$(var##pattern)
现在分述如下:
1.Shell中变量的原形:${var}
大家常见的变量形式都是$var,如
$ var=test
$ echo $var
但当你要显示变量值加随意的字符(我这里用AA)时,就会出错,如下:
$ echo $varAA
这时应该用变量的原形:${var},即是加一个大括号来限定变量名称的范围,如下
$ echo ${var}AA
以这个特性,我们可以很方便地写一个批量改后缀名的程序,我把它命名为mymv,程序如下:
#!/bin/bash
for filename in `ls`
mv $filename ${filename}.$tail
程序需要提供一个后缀名,如c,表示改为后缀为c的C程序文件,看下面的测试:
a.c b.c c.c
看样子程序运行的很好,但这是不完善的程序,有2个要注意的问题:
A,目录下没有子目录,如果有一个目录,假设为dir,则也会被改为dir.c,这显然不是我们想要的,应该修正这个程序能识别目录。
B,没有帮助对程序的参数进行处理,程序应该足够友好,在用户没有给定后缀名时应能处理,像上面的将直接给文件加上了一个点(.),这显然也不是我们想要的。
因为我们的目的是说明${var},这样已经足够了,因此这里不会再对上面的程序进行修正。
2.命令替换$(cmd)
命令替换$(cmd)和符号`cmd`(注意这不是单引号,在美式键盘上,`是ESC下面的那个键)有相同之处
$ echo $(ls)
$ echo `ls`
我们来分析一下命令echo $(ls),以便理解所谓命令替换是什么意思:
shell扫描一遍命令行,发现了$(cmd)结构,便将$(cmd)中的cmd执行一次,得到其标准输出,再将此输出放到原来命令echo $(ls)中的$(ls)位置,即替换了$(ls),再执行echo命令。
echo $(ls)被替换成了echo a b c
这里要注意的是$(cmd)中的命令的错误输出是不会被替换的,替换的只是标准输出:
$ var=$(cat d) ###文件d在当前目录不存在
cat: d: 没有那个文件或目录
$ echo $var
$ ###显然var变量的值是空的
3、一串的命令执行()和{}
()和{}都是对一串的命令进行执行,但有所区别:
A,()只是对一串命令重新开一个子shell进行执行
B,{}对一串命令在当前shell执行
C,()和{}都是把一串的命令放在括号里面,并且命令之间用;号隔开
D,()最后一个命令可以不用分号
E,{}最后一个命令要用分号
F,{}的第一个命令和左括号之间必须要有一个空格
G,()里的各命令不必和括号有空格
H,()和{}中括号里面的某个命令的重定向只影响该命令,但括号外的重定向则影响到括号里的所有命令
我们来看几个例子:
$ var=test
$ (var= echo $var) ###变量var值为notest,此是在子shell中有效
$ echo $var ###父shell中值仍为test
$ { var= echo $} ###注意左括号和var之间要有一个空格
$ echo $var ###父shell中的var变量的值变为了notest
$ { var1=test1;var2=test2;echo $var1&a;echo $var2;} ###输出test1被重定向到文件a中,
test2 ###而test2输出则仍输出到标准输出中。
$ { var1=test1;var2=test2;echo $var1;echo $var2;}&a ###括号内命令的标准输出全部被重定向到文件a中
下面是一个脚步例子:
&&& echo "1"
&&& echo "2"
) | awk &{print NR,$0}&
4,几种特殊的替换结构:${var:-string},${var:+string},${var:=string},${var:?string}
A,${var:-string}和${var:=string}
若变量var为空,则用在命令行中用string来替换${var:-string},否则变量var不为空时,则用变量var的值来替换${var:-string}
$ echo $newvar
$ echo ${newvar:-a}
$ echo $newvar ###变量newvar的值仍然是空,但上一命令行中${newvar:-a}被替换成了a
$ newvar=b
$ echo ${newvar:-a} ###变量newvar的值不为空时,此命令行中的${newvar:-b}被替换为$newvar,即b
对于${var:=string}的替换规则和${var:-string}是一样的,所不同之处是${var:=string}若var为空时,用string替换${var:=string}的同时,把string赋给变量var:
$ echo $newvar
$ echo ${newvar:=a}
$ echo $newvar ###变量newvar被赋值为a,同时${newvar:=a}被替换成a
$ echo ${newvar:=b} ###变量newvar不为空(其值已被赋为a),则${newvar:=b}被替换为newvar的值(即b)
$ echo $newvar
${var:=string}很常用的一种用法是,判断某个变量是否赋值,没有的话则给它赋上一个默认值。
如设置默认的编辑器:
echo You use editor: ${EDITOR:=/bin/vi}
B,${var:+string}
${var:+string}的替换规则和上面的相反,即只有当var不是空的时候才替换成string,若var为空时则不替换或者说是替换成变量 var的值,即空值。(因为变量var此时为空,所以这两种说法是等价的)
$ echo $newvar
$ echo ${newvar:+b}
$ echo $newvar
$ echo ${newvar:+b}
C,${var:?string}
替换规则为:若变量var不为空,则用变量var的值来替换${var:?string};若变量var为空,则把string输出到标准错误中,并从脚本中退出。我们可利用此特性来检查是否设置了变量的值。
$ echo ${newvar:?没有设置newvar的值}
bash: newvar: 没有设置newvar的值
$ newvar=a
$ echo ${newvar:?没有设置newvar的值}
补充扩展:在上面这五种替换结构中string不一定是常值的,可用另外一个变量的值或是一种命令的输出。
$ echo ${var:-`date`}
日 3月 6 02:10:39 CST 2005
$ echo ${var:-$(date)}
日 3月 6 02:11:46 CST 2005
$ echo ${var:-$a}
5.POSIX标准的扩展计算:$((exp))
这种计算是符合C语言的运算符,也就是说只要符合C的运算符都可用在$((exp)),甚至是三目运算符。
注意:这种扩展计算是整数型的计算,不支持浮点型.若是逻辑判断,表达式exp为真则为1,假则为0。
$ echo $((3+2))
$ echo $((3&2))
$ echo $((25&3 ? 2:3))
$ echo $var
$ echo $((var=2+3))
$ echo $var
$ echo $((var++))
$ echo $var
好了,上面的例子足够了,这也表明了这种扩展运算是很强大的。
6.四种模式匹配替换结构:${var%pattern},${var%%pattern},${var#pattern},${var##pattern}
这四种结构的意义是:${var%pattern}和${var%%pattern}表示从最右边(即结尾)匹配的,${var#pattern} 和${var##pattern}从最左边(即开头)匹配的。其中${var%pattern}和${var#pattern}是最短匹 配,${var%%pattern}和${var##pattern}是最长匹配。只有在pattern中使用了通配符才能有最长最短的匹配,否则没有最 长最短匹配之分。
结构中的pattern支持通配符,*表示零个或多个任意字符,?表示零个或一个任意字符,[...]表示匹配中括号里面的字符,[!...]表示不匹配中括号里面的字符。
$ var=aabbbccbbdbb
$ echo ${var%b}
aabbbccbbdb
$ echo ${var%%b}
aabbbccbbdb
$ echo ${var#a}
abbbccbbdbb
$ echo ${var##a}
abbbccbbdbb
$ echo ${var%*b}
aabbbccbbdb
$ echo ${var%%*b}
$ echo ${var#a*}
abbbccbbdbb
$ echo ${var##a*}
上面是简单的例举四种模式匹配替换结构的用法。
•其他(见man bash中的Parameter Expansion)
${parameter/pattern/string}
&&&&&&&&&&&&& Pattern substitution.& The pattern is expanded to produce a pat‐
&&&&&&&&&&&&& tern& just& as in pathname expansion.& Parameter is expanded and
&&&&&&&&&&&&& the longest match of pattern against its value is replaced& with
&&&&&&&&&&&&& string.&& If& pattern& begins with /, all matches of pattern are
&&&&&&&&&&&&& replaced& with& string.&& Normally& only& the& first& match&& is
&&&&&&&&&&&&& replaced.& If pattern begins with #, it must match at the begin‐
&&&&&&&&&&&&& ning of the expanded value of parameter.& If pattern begins with
&&&&&&&&&&&&& %,& it must match at the end of the expanded value of parameter.
&&&&&&&&&&&&& If string is null, matches of pattern are deleted and the / fol‐
&&&&&&&&&&&&& lowing pattern may be omitted.& If parameter is @ or *, the sub‐
&&&&&&&&&&&&& stitution operation is applied to each positional& parameter& in
&&&&&&&&&&&&& turn,& and the expansion is the resultant list.& If parameter is
&&&&&&&&&&&&& an array variable subscripted with& @& or& *,& the& substitution
&&&&&&&&&&&&& operation& is& applied& to each member of the array in turn, and
&&&&&&&&&&&&& the expansion is the resultant list.
(( )) :一对圆括号有两个地方用到。
1,for循环,
for (( expr1 ; expr2 ; expr3 ))
这里一对双括号里边的表达式,GNU的文档指出,expr1支持 Shell Arithmetic;expr2不为0时,expr3被赋值且语句执行。说的很麻烦,还要花时间搞清楚什么是Shell Arithmetic。其实一言以蔽之,支持数字条件。比如:
for (( a=0 ; a&10 ; a++ )); do echo $a; done
会输出 0 1 2 3 (带换行哦~~~)
2,数学表达
(( )) 和 $(( ))
(( )) 的用法与let一样,就不用多解释了吧~~~
$(( ))就是把计算结果拿出来,可以用在双引号里边,比如:
echo "1+2=$(( 1 + 2 ))"
会输出 1+2=3
( ):一个圆括号
在for循环里,跟C语法一样一样的。
或者是子程序,返回整个里边表达的返回值。里边的变量都是局部的,修改不会带到外边。举例子
(a=3; echo $a)
结果是 3 1
还有个就是圈数组。。。这个就没神马意思了
[ ]:一个方括号,是bash的命令,查man手册是可以查到的,跟test一样,在手册里可以看到很多用法。比如-b -c -gt -eq 什么的很多,还有用-a表示与,-o表示或等等
[[ ]]:一对方括号是一个方括号的加强版,则是Shell的保留字,里边支持了 || && 等等这些符号。一般我喜欢用这个
还有相对复杂的 { }
几个用处,区分变量,如:
var= echo ${var}EFG;
这样,Bash就不会认为变量是varEFG了
还有用来截取字符串的 ${ }语法比较灵活多变,这里不做多解释,大家有兴趣可以自己去搜搜资料,一般我脚本用到的字符串处理,这个都能搞定了。
代码块。用来区分代码的,但是跟( )有个区别,就是在末尾要加上 ;
在子shell中运行
(a=1);echo $a,结果是空,因为a=1不是在当前shell中运行的(a=1);(echo $a)也是空的。不在同一个子shell中
数组的赋值,见最后的补充
表达式计算
a=1;((a++)); echo $a,这时a就是2了。
3.&()和&()
进程代入,可以把命令的执行结果当成文件一样读入
比如comm前一般需要sort,那就可以这样comm &(sort 1.lst) &(sort 2.lst)
或者是paste &(cut -t2 file1) &(cut -t1 file1)
,和管道差不多,但是支持多个输入。
$(cmd) 执行cmd的结果,比如cmd是echo ls,那么就是执行ls,比如file$(which bash),which bash的结果是/bin/bash,所以file $(which bash)等于file /bin/bash。如果你$(ls),而且你的当前目录下只有a b两个文件,那么就是执行a b,然后系统会提示,命令没找到。
表达式扩展,和(())很相似,但是这个是有点不同,$(())不能直接$((b++)),b=1;echo $((++b))这时b等于2,显示的也是2,b=1;echo $((b++))这时b等于2,显示的是1.
6.[]和[[]]
[]就是 test,[]和[[]]都是条件表达式,不过[[]]有比[]高的容错性,如果a为空,那么[ $a -eq 0 ]会报错,但是[[ $a -eq 0 ]]不会,所以一般都会使用[[]]或者是[ "$a" -eq 0 ],[[]]支持的功能也比[]多,比如[[ aaa =~a{3} ]],
[] 还有一种用途,如果你的当前目录下有a1-a9九个文件,你可以用a[1-9]来替代这九个文件。有点需要注意,你不能用a[1-20]来代替a1- a20,必须要a[1-9] a1[0-9] a20。
$(())的过去形式,现在已经不建议使用
{1..30} 就是1-30,或者是/{,s}bin/表示/bin/和/sbin/,ab{c,d,e}表示abc、abd、abe
变量,用法很多,可以查看man bash。
先写这些,以后想到再补充吧。
补充:()同时也是数组的赋值,比如a=(1 3 5),那么${a[0]}=1;${a[1]}=3;${a[2]}=5,需要注意的是,下标是从0开始的
Shell中的括号有其特殊的用法, 现总结如下:
1. 符号$后的括号
${a} 变量a的值, 在不引起歧义的情况下可以省略大括号.
$(cmd) 命令替换, 结果为shell命令cmd的输出, 和`cmd`效果相同, 不过某些Shell版本不支持$()形式的命令替换, 如tcsh.
$((exp)) 和`expr exp`效果相同, 计算数学表达式exp的数值, 其中exp只要符合C语言的运算规则即可, 甚至三目运算符和逻辑表达式都可以计算.
2. 多条命令执行
(cmd1;cmd2;cmd3) 新开一个子shell顺序执行命令cmd1,cmd2,cmd3, 各命令之间用分号隔开, 最后一个命令后可以没有分号.
{ cmd1;cmd2;cmd3;} 在当前shell顺序执行命令cmd1,cmd2,cmd3, 各命令之间用分号隔开, 最后一个命令后必须有分号, 第一条命令和左括号之间必须用空格隔开.
对{}和()而言, 括号中的重定向符只影响该条命令, 而括号外的重定向符影响到括号中的所有命令.
3. 双括号的特殊用法
(()) 增强括号的用法, 常用于算术运算比较. 双括号中的变量可以不使用$符号前缀, 只要括号中的表达式符合C语言运算规则, 支持多个表达式用逗号分开.
比如可以直接使用for((i=0;i&5;i++)), 如果不使用双括号, 则为for i in `seq 0 4`或者for i in {0..4}.
再如可以直接使用if (($i&5)), 如果不使用双括号, 则为if [ $i -lt 5 ].
[[]] 增强方括号用法, 常用于字符串的比较. 主要用于条件测试, 双括号中的表达式可以使用&&, ||, &, &等C语言语法.
比如可以直接使用if [[ $a != 1 && $a != 2 ]], 如果不适用双括号, 则为if [ $a -ne 1] && [ $a != 2 ]或者if [ $a -ne 1 -a $a != 2 ].
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具

我要回帖

更多关于 c语言echo 的文章

 

随机推荐