![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
K Shell 基本语法知识
gorden
这个作者很懒,什么都没留下…
展开
-
解释 kshell语法中 双引号“”单引号 ‘’ 和反斜杠\ 的作用以及执行规则
解释1.双引号““,使包含在里边的字符串失去意义,不起作用,除了四个字符$ ` " 和\外。2.单引号 ` `,使包含在里边的字符串失去意义,不起作用。3.反斜杠 \,使紧跟在 \后面的字符正常显示,转义符。1.Example$ s=“hello” # assign a value to a variable$ print “$s” # output the value原创 2012-10-10 17:32:50 · 1540 阅读 · 0 评论 -
解释 kshell的通配符星号* 中括弧[chars] 问号? 和波浪号~的用法以及执行规则
解释1.星号 * ,用来匹配任意字符串,包括null。2.中括弧 [ chars],用来匹配一个包含在括弧中间的字符。3.问号 ? ,用来匹配任意一个字符。4.波浪号 ~,用来匹配当前用户的home目录1.Example$ ls x*x x1 x2 x3 xfour2.Example$ lsx x1 x2 x原创 2012-10-11 14:17:24 · 2009 阅读 · 0 评论 -
kshell 如何查看历史命令 以及执行历史命令 hsitory r[number] r[chars]的语法以及用法
1.history ,用来显示最新执行的15条命令。例:$ history40 cd ~gorden41 ls42 ls [xyz]*43 ls [xyz]?44 ls45 ls x*46 su - root47 su - root48 su - root4原创 2012-10-12 17:01:22 · 2366 阅读 · 0 评论 -
kshell 如何传递参数给shell和调用参数 以及设置参数的默认值
Example$ ksh shell_script arg1 arg2 ... arg9 arg10 arg11 ...shell_script是shell脚本文件名,而紧跟在后面的arg1 ...argN是参数。那么在shell脚本里边我们如何来引用这些参数呢?1.$# 表示所有参数的个数2.$* 表示所有的参数3.$0 表示shell脚本文件名,譬如在上原创 2012-10-15 17:14:47 · 5388 阅读 · 0 评论 -
kshell 标准输入输出 >(重新输出) >>(追加输出) 以及2>(标准错误输出)以及输出重定向/dev/null
1.> 将目标文件清空后输出Example$ set -o noclobber # 防止覆盖文件$ date > whofilewhofile: file already exists$ date >| whofile$ cat whofileThu Feb 1 13:38:36 EST 1998$ set +o noclobber # clear noclobb原创 2012-10-16 14:22:06 · 1017 阅读 · 0 评论 -
怎么写第一个kshell 以及如何执行kshell
如何写一个标准的kshell#cat helloworld.ksh#!/bin/usr/kshprint "hello world ,kshell"如何执行shell#ksh helloworld.kshhello world,kshell或者#./helloworld.ksh #需要执行权限x如何查看执行结果#print "$?" #打印出执行原创 2012-10-17 16:59:00 · 2410 阅读 · 0 评论 -
kshell 如何比较两个数值或字符串 "test" [[ ]]" "(())" "[ ]"
KronShell提供了四种方法来对比两个值:1. [[ ]] — 比较字符串2. (( )) — 比较数字3. test command — 支持Bourne shell 和KornShell4. []— 支持Bourne shell 和 KornShell例1:if [[ “$response” = “Yes” ]]thenprint “Oka原创 2012-10-30 15:47:58 · 1001 阅读 · 0 评论