【161】BASH相关文章链接
---恢复内容开始---
- 新建文件 file1.txt,随便输入几行文字
-
cat 'file1.txt' #显示 'file1.txt' 的内容 cat 'file1.txt' > 'file2.txt' #把 'file1.txt' 的内容复制到 'file2.txt' 中 cat -n 'file1.txt' > 'file2.txt' #把 'file1.txt' 的内容复制到 'file2.txt' 中,同时加上数字编号 cat 'file1.txt' 'file2.txt' > 'file3.txt' #将 'file1.txt' 与 'file2.txt' 合并复制到 'file2.txt' 中 cat 'file1.txt' 'file2.txt' >> 'file3.txt' #效果同上 cat -b 'file1.txt' 'file2.txt' > 'file3.txt' #加上行号blahblah
-
注意:上面的文本文件不加引号也是可以的!
3. 为txt文件赋值
- bash shell 基础(语法)
- &>/dev/null 等价于 >/dev/null 2>&1
- shell getopts 用法
- bash exit
- 通过“./test.sh”执行文件,修要增加代码
$ chmod u+x test.sh
- 提取字符串中的内容
#提取钱四个字符,0表示位置,4表示个数 $ str="alexbnlee" $ echo ${str:0:4} #取string 的第1到第4个字符,从1开始计数 $ echo $str|cut -c 1-4
参考:shell 如何判断某个文件名以某个字符开头~
参考:shell 字符串处理汇总(查找,替换等等)
参考:Bash Shell字符串操作小结
- 获取文件名称和扩展名
file=”thisfile.txt” echo “filename: ${file%.*}” echo “extension: ${file##*.}” #输出: filename: thisfile extension: txt
- 字符串包含关系
string="alexbnlee" substring="bn" if [[ $string == *$substring* ]] then echo "包含!" fi if [[ $string != *$substring* ]] then echo "不包含!" fi
参考:shell 判断字符串是否存在包含关系