#!/bin/bash
echo "enter a number"
#read input value
read ans
#case
case $ans in
1)
echo "your number is $ans"
;;
2)
echo "your number is 2"
;;
[3-9])
echo "your number is $ans"
esac
echo "Parameter numbers:$#"
echo "Shell name:$0"
echo "Shell all parameters:$*"
echo "Shell PID:$$"
echo "Shell PPID:$!"
echo "Before command return value:$?"
#echo "get command return:$(ls /home/provision)"
#if : -eq(==) -ne(!=) -lt(<) -gt(>) -ge(>=) -le(<=)
if [ "22" -lt "33" ]
then
echo "22 less than 33"
else
echo "22 not less than 33"
fi
#while
#no space left or right =
num=1
echo "init num = $num"
#need space after [ ,before ]
while [ $num -le 10 ]
do
echo "num=$num"
let num=num+1
done
#file exist
fileName="case_test.sh"
if [ -e $fileName ]
then
echo "$fileName is exist:"
else
echo "$fileName is not exist:"
fi
#is directory
if [ -d $fileName ]
then
echo "$fileName is directory"
else
echo "$fileName is not directory"
fi
if [ -z $fileName ]
then
echo "fileName length is 0"
else
echo "fileName length is not 0"
fi
if [ -n $fileName ]
then
echo "fileName length is not 0"
else
echo "fileName length is 0"
fi
#
for filename in `ls`
do
cat $filename
done
for((i=0; i<10; i++))
do
echo "--$i"
done
echo "Name:${name:-huangxiaobing}"
#function return only number cannot return string
getName(){
return 100
}
getName
echo "getName:$?"
#connect two string
firstname="huang"
lastname="xiaobing"
allname=`printf "%s%s" "$firstname" "$lastname"`
echo "All Name:$allname"
#get the char count of string
countChar=`echo "$firstname"|wc -m`
echo "$firstname count:$countChar"
#return nor number char: return null
echo "12345"|sed 's/[0-9]//g'
#return A
echo "123A45"|sed 's/[0-9]//g'
#return huang
echo ${allname%%xiaobing}
echo ${allname:0:5}
echo ${allname:2:7}
分享到:
相关推荐
shell 字符串操作 关于字符的常用命令
本文阐述:shell中整数比较方法及字符串的比较方法,如等于,不等于,大于,大于等于,小于,等等
本文由TinyLab.org原创。 本文是自由书籍《Shell编程...第三、对串的常规操作:求子串、插入字符、删除字符、置换字符、字符串的比较等。 第四、对串的一些比较复杂而有趣的操作,这里将在最后介绍一些有趣的范例。
shell中字符串截取shell中字符串截取shell中字符串截取shell中字符串截取shell中字符串截取shell中字符串截取shell中字符串截取shell中字符串截取shell中字符串截取shell中字符串截取shell中字符串截取shell中字符串...
shell数组循环 测试shell数组,循环的例子: arr=(a b c) echo 所有的内容如下:${arr[@]} echo 数组的长度:${#arr[*]} ... 您可能感兴趣的文章:Shell获取字符串长度的多种方法总结用Shell判断字符串包含
shell脚本语法:shell脚本写法:复杂数学式,字符串,布尔值,case写法
shell 字符串 截取 查找 替换 shell 字符串 截取 查找 替换 shell 字符串 截取 查找 替换 shell 字符串 截取 查找 替换
在做shell批处理程序时候,经常会涉及到字符串相关操作。有很多命令语句,如:awk,sed都可以做字符串各种操作。 其实shell内置一系列操作符号,可以达到类似效果,大家知道,使用内部操作符会省略启动外部程序等时间...
shell中字符串处理方式,Linux下灵活活处理字符串的说明。。
linux shell 字符串的截取
Linux Shell字符串比较
NULL 博文链接:https://annan211.iteye.com/blog/2412844
shell 操作字符串
一些需要注意的脚本问题 计算字符串长度可用的三种方法: 代码如下: echo “$str”|awk ‘{print length($0)}’ expr length “$str” ... 您可能感兴趣的文章:用Shell判断字符串包含关系的方法小结Shel
运行级别脚本的结构 某产品运行级别脚本示例 添加和管理启动脚本
将需要替换的文件放到脚本同级目录,直接执行脚本即可。 根据脚本提示输入 替换前和替换后的字符串
以下给出一些shell中判断字符串包含的方法,来源程序员问答网站 stackoverflow 以及segmentfault。 方法一:利用grep查找 strA=long string strB=string result=$(echo $strA | grep ${strB}) if [[ $result != ]] ...
我们有这样一个字符串: 代码如下: info=’abcd;efgh’ 现在想获取abcd和efgh,我们可以简单地用cut工具来获取: ... 您可能感兴趣的文章:Shell获取字符串长度的多种方法总结用Shell判断字符串包含
linux_shell编程入门书籍,配合实例讲解,有助于新手入门,欢迎下载