几种shell里的小括号,大括号结构和有括号的变量,命令的用法(The parentheses, braces, parentheses, variables, and commands used in several shell).docVIP
- 1、本文档共15页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 5、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 6、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 7、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 8、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
几种shell里的小括号,大括号结构和有括号的变量,命令的用法(The parentheses, braces, parentheses, variables, and commands used in several shell)
几种shell里的小括号,大括号结构和有括号的变量,命令的用法(The parentheses, braces, parentheses, variables, and commands used in several shell)
What I want to say here is a few parentheses in shell, braces and parentheses, and the use of commands, as follows:
1.${var}
2.$(CMD)
(3.) and {}
4.${var:-string}, ${var:+string}, ${var:=string}, ${var:, string}
5.$((EXP))
6.$(var%pattern), $(var%%pattern), $(var#pattern), $(var##pattern)
Now read the following:
The prototype of variables in 1.Shell: ${var}
The common form of variables is $var, such as
$var=test
$echo $var
Test
But when you want to display variable values with optional characters (I use AA here), you go wrong, as follows:
$echo $varAA
$
You should then use the prototype of the variable: ${var}, that is, adding a brace to limit the range of variable names, as follows
$echo ${var}AA
TestAA
$
With this feature, we can easily write a batch to change the suffix name of the program, I named it mymv, the program follows:
# /bin/bash!
Tail=$1
For filename in `ls`
Do
MV $filename ${filename}.$tail
Done
The program needs to provide a postfix name, such as C, which represents the C program file with the suffix C. See the following test:
$LS
A B C
$mymv C
$LS
A.C B.C C.C
$
It seems that the program is running well, but this is incomplete procedures, there are 2 issues to pay attention to:
A, there is no subdirectory in the directory. If there is a directory, assuming it is dir, it will be changed to dir.c, which is obviously not what we want. It should be modified to recognize the directory.
B, without the help of the program processing parameters, procedures should be friendly enough, should be able to handle the user without a suffix, like the above will go directly to the file with a dot (.), this is obviously not what we want.
Because our purpose is to explain ${var}, this is enough, so there will be no modification to the above program.
The 2. command replaces $(CMD)
Command replace $(CMD) and symbol `cmd` (note that this is not a single quo
您可能关注的文档
- 人才的世界杯之战(Talent World Cup battle).doc
- 人才的留与流(Talent retention and flow).doc
- 人才管理的伪命题(The pseudo proposition of talent management).doc
- 人才管理在企业管理中的重要作用(The important role of talent management in enterprise management).doc
- 人才离开日企的六个理由(Six reasons for talents leaving Japan).doc
- 人才结构的层次(Hierarchy of personnel structure).doc
- 人才重要(Important talent).doc
- 人教a必修2第二章《点、直线、平面之间的位置 - 成(People teach a required 2, second chapters, point, line, plane position between - into).doc
- 人教a版高中数学课程标准实验教科书 (必修3第三章)(People teach a version of high school mathematics curriculum standards experimental textbooks (compulsory 3, third chapters)).doc
- 人教新课标版初中八上4.2熔化和凝固基础训练题(People teach the new curriculum version junior high school eight on 4.2 melting and solidification basic training questions).doc
文档评论(0)