- 论坛徽章:
- 0
|
----------------functions.sh-----------------------
#!/bin/sh
chop()
{
_STR=$1
_CHOP=$2
_CHOP=`expr $_CHOP + 1`
if [ $# -ne 2 ]; then
echo "check_length: I need a string and how many characters to chop"
return 1
fi
_LENGTH=`echo $_STR|awk '{ print length($0)}'`
if [ "$_LENGTH" -lt "$_CHOP" ];then
echo "sorry ,you have asked to chop more characters than there are in the string"
return 1
fi
echo $_STR|awk '{print substr($1,'$_CHOP')}' #%%%%%%%%%%%
}
------------------------test.sh--------------------------------
#!/bin/sh
#name:test
if [ -r /root/chop ];then
. /root/chop
fi
echo "start now..."
CHOPPED=`chop "Honeysuckle" 5`
echo $CHOPPED
echo "end now."
function.sh是一个函数文件. test.sh调用该函数文件.
我的问题是:带有#%%%%%%%%%%%%符号的那行为什么$1两侧没有单引号,而$_CHOP变量两边却有单引号.(我知道这行的单引号的作用是这样的:
'{print substr($1,'-----$_CHOP-----')}' ,分成这么三部分) |
|