This is the mail archive of the
cygwin@cygwin.com
mailing list for the Cygwin project.
Re: [[ ]] test always reports a "not found" error in bash shell scrip t
- From: Randall R Schulz <rschulz at sonic dot net>
- To: cygwin at cygwin dot com
- Date: Thu, 26 Jun 2003 10:50:26 -0700
- Subject: Re: [[ ]] test always reports a "not found" error in bash shell scrip t
Michael,
At 09:21 2003-06-26, MATTHEWS,MICHAEL (HP-Vancouver,ex1) wrote:
Thu 2003/JUN/26 0921 PDT
Hello,
I am porting a Linux build system to Windows XP by using the Cygwin 1.3.22-1
environment (see the attached text file for output from "cygcheck -s -v
-r"). All of the bash shell scripts use the [[ ]] test in if statements,
similar to:
if [[ "$(uname -s)" != "Linux" ]]
then
# Do Cygwin stuff
else
# Do Linux stuff
fi
Whenever I run the script in the Cygwin bash shell, the conditional
executes, but the following error is displayed in the terminal window:
[[: not found
My guess is that your scripts begin with something like this:
#!/bin/sh
Under cygwin, this invokes ash, not BASH.
If I replace the double square brackets with single square brackets:
if [ "$(uname -s)" != "Linux" ]
then
# Do Cygwin stuff
else
# Do Linux stuff
fi
I do not get any error message.
I use the [[ ]] test because from what I read about the bash shell
conditional testing, using [[ ]] is better than [ ], since [[ ]] is tested
internally, whereas [ ] is tested in a separate shell with the "test"
command. I would prefer to not have to change all of the test conditionals
in our Linux bash shell scripts from [[ ]] to [ ].
Background information from my Cygwin:
BASH_VERSINFO=([0]="2" [1]="05b" [2]="0" [3]="9" [4]="release"
[5]="i686-pc-cygwin")
BASH_VERSION='2.05b.0(9)-release'
% bash --version
GNU bash, version 2.05b.0(9)-release (i686-pc-cygwin)
Copyright (C) 2002 Free Software Foundation, Inc.
% help [
[: [ arg... ]
This is a synonym for the "test" builtin, but the last
argument must be a literal `]', to match the opening `['.
[[ ... ]]: [[ expression ]]
Returns a status of 0 or 1 depending on the evaluation of the conditional
expression EXPRESSION. Expressions are composed of the same
primaries used
by the `test' builtin, and may be combined using the following operators
( EXPRESSION ) Returns the value of EXPRESSION
! EXPRESSION True if EXPRESSION is false; else false
EXPR1 && EXPR2 True if both EXPR1 and EXPR2 are true; else false
EXPR1 || EXPR2 True if either EXPR1 or EXPR2 is true; else false
When the `==' and `!=' operators are used, the string to the right of the
operator is used as a pattern and pattern matching is performed. The
&& and || operators do not evaluate EXPR2 if EXPR1 is sufficient to
determine the expression's value.
Two things are germane here:
1) [[ ... ]] _is_ available in Cygwin BASH (of course).
2) The distinction between [ ... ] and [[ ... ]] is not what you seem
to think it is. In particular, they're both BASH built-ins.
I checked the versions of bash in Cygwin and in Linux and they are:
Cygwin bash version : GNU bash, version 2.05b.0(9)-release
(i686-pc-cygwin)
Linux bash version : GNU bash, version 2.05b.0(1)-release
(i686-pc-linux-gnu)
The version of Linux we are using is Red Hat 8.0 Linux.
-Michael
Randall Schulz
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/