LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 704|回复: 3

脚本的变量??

[复制链接]
发表于 2004-7-7 11:52:34 | 显示全部楼层 |阅读模式
#vi auto.sh
*******************************************************
#!/bin/bash
test1=${1-happyl}
echo 'this is $test1:'$test1
echo 'this is $test1:'$t '$1:'$1
testp=${p=happyp}
echo 'this is $testp:'$testp
echo 'this is $testp:'$p
tests=${3?=fs}
echo 'this is $tests:'$tests '$3:'$3
testb=${b+happyb}
echo 'this is $testb:'$testb'$4:'$4
********************************************************
#. auto.sh
********************************************************
this is $test1:happyl
this is $test1: $1:
this is $testp:happyp
this is $testp:happyp
bash: 3: =fs
this is $tests: $3:
this is $testb4:
********************************************************
Why???
发表于 2004-7-7 16:11:20 | 显示全部楼层

我今天也碰到类似问题!!

你的在我这儿运行结果不一样!
this is $test1:
this is $test1: $1:
this is $testp:happyp
this is $testp:happyp
./auto.sh: line 7: 3: =fs
 楼主| 发表于 2004-7-7 19:00:37 | 显示全部楼层
tests=${3?=fs}
在这一行里的?不是说如果给3附值之后就退出了吗?为什么还会继续进行4,5行?
发表于 2004-7-7 20:54:50 | 显示全部楼层
个人认为这种写法不正确. 如果判断是否有值, 应是${var?msg}. 如果是附值, ${var=default}. ${3?=fs}的结果应是给出"=fs"的error mesg如果$3为null, 所以我不认为bash会"给3附值之后就退出".
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表