写了个函数 #!/bin/sh function getTime { Time=`time` return $Time } getTime CurrentTime=$? echo CurrentTime=$CurrentTime 想让他返回字符串Time,但是运行结果却是0,我怎么才能在shell函数中返回字符串呢? >test1.sh real 0m0.000s user 0m0.000s sys 0m0.000s CurrentTime=0
text
a,d,c
d,d,d
============================
while read $line
a = $(echo $line | awk -F; '{print $1}' )
b = $(echo $line | awk -F; '{print $2}' )
c = $(echo $line | awk -F; '{print $3}' )
echo "processing......"
done
#6.sh length_check() { _STR=$1 _MAX=$2 _LENGTH=`echo $_STR | awk '{print length($0)}'` if [ "$_LENGTH" -gt "$_MAX"]; then return 1 else return 0 fi } length_check 提示if [ "$_LENGTH" -gt "$_MAX"]; then 这一行错误:[: 0: unary operator expected
本帖最后由 myaegean 于 2011-04-05 09:32 编辑 【脚本】 -------------------------------------------------------------------- #!/bin/bash # using the return command in a function dbl() { read -p "Enter a value: " value echo "doubling the value" return $[ $value * 2 ] } result='dbl' echo "The new value is $result" -------------------------------------------------------------------- ...
我的shell函数只能有一个参数$1, #!/bin/sh myfun () { if [ $# -ne 1 ]; then echo "please input one parameter" exit 1 fi echo $1 } string="good good" myfun $string #结束了 我运行我的脚本时出错了,程序判断成有两个参数了。请各位兄弟帮我看一下,先谢谢了。 [ 本帖最后由 cdma313 于 2006-10-17 21:39 编辑 ]