From: John Kelly on

I've been using something like this:

[[ a/bc == [^/]*/*[^/] ]] && echo match

(the "a/bc" is an example value)

to test whether a variable contains a file name having a relative path,
and it worked fine with bash. But then I started using the Interix ksh
and it failed. So I had to read the man pages again ...

Seems bash is liberal about the meaning of "not" here. Bash interprets
^ or ! as "not", but Interix ksh treats ^ literally, and only recognizes
! as "not"

I had always preferred ^ since that's what grep uses within [] to mean
"not", but I guess I will change that habit for shell purposes so I can
run my scripts on Interix ksh.


--
Web mail, POP3, and SMTP
http://www.beewyz.com/freeaccounts.php

From: Chris F.A. Johnson on
On 2010-08-08, John Kelly wrote:
>
> I've been using something like this:
>
> [[ a/bc == [^/]*/*[^/] ]] && echo match
>
> (the "a/bc" is an example value)
>
> to test whether a variable contains a file name having a relative path,
> and it worked fine with bash. But then I started using the Interix ksh
> and it failed.

If you used standard syntax instead of [[ ... ]], you wouldn't have
to worry about portability.


--
Chris F.A. Johnson, author <http://shell.cfajohnson.com/>
===================================================================
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)

From: John Kelly on
On Sun, 8 Aug 2010 21:18:17 +0000 (UTC), "Chris F.A. Johnson"
<cfajohnson(a)gmail.com> wrote:

>On 2010-08-08, John Kelly wrote:
>>
>> I've been using something like this:
>>
>> [[ a/bc == [^/]*/*[^/] ]] && echo match
>>
>> (the "a/bc" is an example value)
>>
>> to test whether a variable contains a file name having a relative path,
>> and it worked fine with bash. But then I started using the Interix ksh
>> and it failed.
>
> If you used standard syntax instead of [[ ... ]], you wouldn't have
> to worry about portability.

I thought [[ ... ]] was portable.


--
Web mail, POP3, and SMTP
http://www.beewyz.com/freeaccounts.php

From: pk on
On Sun, 08 Aug 2010 21:08:13 +0000
John Kelly <jak(a)isp2dial.com> wrote:

>
> I've been using something like this:
>
> [[ a/bc == [^/]*/*[^/] ]] && echo match
>
> (the "a/bc" is an example value)
>
> to test whether a variable contains a file name having a relative path,
> and it worked fine with bash. But then I started using the Interix ksh
> and it failed. So I had to read the man pages again ...
>
> Seems bash is liberal about the meaning of "not" here. Bash interprets
> ^ or ! as "not", but Interix ksh treats ^ literally, and only recognizes
> ! as "not"
>
> I had always preferred ^ since that's what grep uses within [] to mean
> "not", but I guess I will change that habit for shell purposes so I can
> run my scripts on Interix ksh.

The standard negation in a character class (per POSIX) is indeed "!". Bash
accepts "^" as an extension.


From: William Ahern on
John Kelly <jak(a)isp2dial.com> wrote:
> On Sun, 8 Aug 2010 21:18:17 +0000 (UTC), "Chris F.A. Johnson"
> <cfajohnson(a)gmail.com> wrote:

> >On 2010-08-08, John Kelly wrote:
> >>
> >> I've been using something like this:
> >>
> >> [[ a/bc == [^/]*/*[^/] ]] && echo match
> >>
> >> (the "a/bc" is an example value)
> >>
> >> to test whether a variable contains a file name having a relative path,
> >> and it worked fine with bash. But then I started using the Interix ksh
> >> and it failed.
> >
> > If you used standard syntax instead of [[ ... ]], you wouldn't have
> > to worry about portability.

> I thought [[ ... ]] was portable.

Not really. Portability is a fuzzy term, but what POSIX specifies is so
minimal it's as good a baseline as any. POSIX reserves "[[" but leaves its
use unspecified. See POSIX.1-2008, Shell & Utilities volume, section
2.4.

http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_04

Note that the OpenGroup requires assent to their terms for accessing the
document. If you haven't already agreed follow thru here

https://www.opengroup.org/online-pubs-short?DOC=9699919799&FORM=HTML

The spec is so relatively short it's not much of a hassle to read it through
once. That way you can likely exclude as portable anything not well defined
according to POSIX. Of course, it still might not be de facto portable even
if well defined.