1
回答
sh 脚本中 [[ ]] 出错,但在 cli 下正常。
百度AI开发者大赛带你边学边开发,赢100万奖金,加群:418589053   
#!/bin/bash
echo '[[ -f /etc/rc.local ]] && echo yes || echo no'
[[ -f /etc/rc.local ]] && echo yes || echo no
echo '[ -f /etc/rc.local ] && echo yes || echo no'
[ -f /etc/rc.local ] && echo yes || echo no

结果

[[ -f /etc/rc.local ]] && echo yes || echo no
test.sh: 3: [[: not found
no
[ -f /etc/rc.local ] && echo yes || echo no
yes

但在 cli 下却正常

~# [[ -f /etc/rc.local ]] && echo yes || echo no
yes

bash 版本

~# bash --version
GNU bash, version 4.1.5(1)-release (i486-pc-linux-gnu)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

debian 版本

~# lsb_release -a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 6.0.3 (squeeze)
Release:	6.0.3
Codename:	squeeze

请教是怎么回事?

举报
neverno
发帖于6年前 1回/124阅
顶部