当前位置: 技术问答>linux和unix
bash [: two many arguments
来源: 互联网 发布时间:2016-05-19
本文导语: str() { if [ $# -ne 2 ] then echo "usage: str string length" return 1 fi sublen='expr $2 + 1 ' len=`echo $1| awk '{ print length($1)}'` if [ $len -lt $sublen ] then echo "your sublen is greater than th...
str()
{
if [ $# -ne 2 ]
then
echo "usage: str string length"
return 1
fi
sublen='expr $2 + 1 '
len=`echo $1| awk '{ print length($1)}'`
if [ $len -lt $sublen ]
then
echo "your sublen is greater than the length of the string"
return 1
fi
echo $1|awk '{print substr($1,$sublen)}'
}
函数功能就是str string L ,从L+1,取string的子串,调用时出现bash [: two many arguments错误不知道为什么
{
if [ $# -ne 2 ]
then
echo "usage: str string length"
return 1
fi
sublen='expr $2 + 1 '
len=`echo $1| awk '{ print length($1)}'`
if [ $len -lt $sublen ]
then
echo "your sublen is greater than the length of the string"
return 1
fi
echo $1|awk '{print substr($1,$sublen)}'
}
函数功能就是str string L ,从L+1,取string的子串,调用时出现bash [: two many arguments错误不知道为什么
|
str()
{
if [ $# -ne 2 ]
then
echo "usage: str string length"
return 1
fi
sublen=`expr $2 + 1` # 符号写错了
len=`echo $1| awk '{ print length($1)}'`
if [ $len -lt $sublen ]
then
echo "your sublen is greater than the length of the string"
return 1
fi
echo $1|awk "{print substr($1,$sublen)}" # 需要参数替换,不能用单引号
}