Revision [1919]

Last edited on 2014-06-15 16:59:41 by DavidLee
Additions:
FILE1 and FILE2 have the same canonical path
====Sequences====
XDM Sequences are evaluated as "Effective Boolean" but only if they appear as a single value. This can cause runtime
errors if you dont know ahead of time if a sequence is 0,1 or more.
Example:
The following is evalutated according to the [http://www.w3.org/TR/xpath20/#id-ebv Effective Boolean] rule of XPath.
In this case a sequence of non atomic elements of 1 or more is "true"
x=<[ <foo/> ]> # XML sequence of 1
[ $x ] && echo true
One might expect this also to work
x=<[ <foo/> , <bar/> ]>
[ $x ] && echo true
Results in
**{{color fg="#FF0000" text="[:Unexpected xml value operator"}} **
The problem is that $x is expanded in command mode and evaluates to 2 arguments not one. The resulting expression is equivalent to
[ <foo/> <bar/> ] && echo true
Which the ""["" command doesnt expect. To get the desired results either wrap the expression in an XQuery expression and XPath expression that evaluates to an atomic, like exists()
or quote the variable with {} which prevents expansion into multple words, preserving the value as a single arugment of type sequence.
Either of these will work
x=<[ <foo/> , <bar/> ]>
[ <[ exists( $x ) ]> ] && echo true
x=<[ <foo/> , <bar/> ]>
[ {$x} ] && echo true
Be aware that the former expression only returns true if $x is not empty, wheras the later uses the [http://www.w3.org/TR/xpath20/#id-ebv Effective Boolean] rules.
For example the following test evaluates false even though the list is not empty
x=<[ fn:false() ]>
[ {$x} ] && echo This will not echo
if you really want to tell if a list is empty use the former version or equivilent (such as ""count($x) gt 0)"" ) or use the variable sequence count expression
[ ${#x} -ne 0 ] && echo The list is not empty
You can also convert the result to a string and compare for empty using -n or -z. For XML expressions the string serialization rules will be used which
does not always produce a non empty string for sequences (such as attributes) and can also produce very large strings which are inefficient to serialize.
Examples:
x=<[ <foo a=""/>/@a ]>
echo \$x is "$x" count ${#x}
[ -z "$x" ] && echo true || echo false
y=<[ $x/string() ]>
echo \$y is "$y" count ${#y}
[ -z "$y" ] && echo true || echo false
Result
$x is a="" count 1
false
$y is count 1
true
This is because $x is an attribute node that when implicitly serialized produces a="" but when explicitly converted to a string using the string() function produces "" (an empty string)
[[ CategoryCommands]]
Deletions:
FILE1 and FILE2 have the same cananocal path
[[CategoryCommands]]


Revision [1075]

Edited on 2009-11-30 11:28:17 by DavidLee
Additions:
**-D name**
true if the environment variable "name" is defined


Revision [1028]

Edited on 2009-11-25 14:42:58 by DavidLee
Additions:
====XML Expressions====
An XML Expression within the test command is evaluated to boolean and the result used for the expression.
A simplistic example
%%
[ <[ fn:true() ]> ] && echo true
%%
A more interesting example
%%
a=<[ <foo attr="bar"/> ]>
if [ <[ $a/@attr eq 'bar' ]> ] ; then
echo attr is bar
fi
%%
Note the spaces needed before and after the [ and ]


Revision [1027]

Edited on 2009-11-25 14:40:17 by DavidLee
Additions:
[[Commands]]


Revision [754]

Edited on 2009-09-16 07:52:54 by DavidLee
Deletions:
[[CommandsBuiltin]]


Revision [387]

Edited on 2009-01-05 19:06:07 by DavidLee
Additions:
TRUE if string is formated as an absolute URI (starts with <scheme>: )
Deletions:
TRUE if string is formated as an absolute URI (starts with <scheme>:\/[/ )


Revision [386]

Edited on 2009-01-05 19:05:54 by DavidLee
Additions:
TRUE if string is formated as an absolute URI (starts with <scheme>:\/[/ )
Deletions:
TRUE if string is formated as an absolute URI (starts with <scheme>:// )


Revision [385]

Edited on 2009-01-05 19:04:38 by DavidLee

No Differences

Revision [384]

Edited on 2009-01-05 19:04:30 by DavidLee
Additions:
**test** expr
**[** expr **]**
Deletions:
*test* expr
*[* expr *]*


Revision [383]

Edited on 2009-01-05 19:04:17 by DavidLee
Additions:
======Command test======
======Synopsis======
*test* expr
*[* expr *]*
**-u string**
TRUE if string is formated as an absolute URI (starts with <scheme>:// )
Deletions:
======test expr======
======[ expr ]======


Revision [344]

Edited on 2009-01-03 06:46:33 by DavidLee
Additions:
[[CategoryCommands]]


Revision [225]

Edited on 2008-06-08 15:07:26 by DavidLee
Additions:
true if the value/argument is a string //type //(not an xml type)
true if the value/argument is an xml //type//
Deletions:
true if the value/argument is a string (not an xml type)
true if the value/argument is an xml type


Revision [224]

Edited on 2008-06-08 15:07:03 by DavidLee
Additions:
**-S value**
true if the value/argument is a string (not an xml type)

**-X value**
true if the value/argument is an xml type


Revision [180]

Edited on 2008-05-31 17:56:23 by DavidLee
Additions:
**-w FILE**
Deletions:
-w FILE


Revision [179]

Edited on 2008-05-31 17:55:59 by DavidLee
Additions:
**-f FILE**
**-r FILE**
**-s FILE**
**-x FILE**
Deletions:
-f FILE
-r FILE
-s FILE
-x FILE


Revision [178]

Edited on 2008-05-31 17:54:38 by DavidLee
Additions:
**EXPRESSION1 -a EXPRESSION2**
**EXPRESSION1 -o EXPRESSION2**
**-n STRING**
**STRING **
equivalent to -n STRING
**-z STRING**
**STRING1 = STRING2**
**STRING1 != STRING2**
**INTEGER1 -eq INTEGER2**
**INTEGER1 -ge INTEGER2**
**INTEGER1 -gt INTEGER2**
**INTEGER1 -le INTEGER2**
**INTEGER1 -lt INTEGER2**
**INTEGER1 -ne INTEGER2**
**FILE1 -ef FILE2**
**FILE1 -nt FILE2**
**FILE1 -ot FILE2**
**-d FILE**
**-e FILE**
Deletions:
EXPRESSION1 -a EXPRESSION2
EXPRESSION1 -o EXPRESSION2
-n STRING
STRING equivalent to -n STRING
-z STRING
STRING1 = STRING2
STRING1 != STRING2
INTEGER1 -eq INTEGER2
INTEGER1 -ge INTEGER2
INTEGER1 -gt INTEGER2
INTEGER1 -le INTEGER2
INTEGER1 -lt INTEGER2
INTEGER1 -ne INTEGER2
FILE1 -ef FILE2
FILE1 -nt FILE2
FILE1 -ot FILE2
-d FILE
-e FILE


Revision [177]

Edited on 2008-05-31 17:52:54 by DavidLee
Additions:
**( EXPRESSION )**
**! EXPRESSION**
Deletions:
( EXPRESSION )
! EXPRESSION


Revision [176]

Edited on 2008-05-31 17:52:33 by DavidLee

No Differences

Revision [175]

The oldest known version of this page was created on 2008-05-31 17:52:23 by DavidLee
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki