From: Nix on
On 12 Mar 2010, Richard Kettlewell told this:

> unruh <unruh(a)wormhole.physics.ubc.ca> writes:
>> [[ is an internal command in bash. I guess it is not in dash.
>> complain to the writers of dash.
>
> It's a Bashism, i.e. not a standard (in the POSIX sense) shell feature.

Actually it's a kshism carried over into bash. (But you knew that.)
From: Nix on
On 12 Mar 2010, unruh(a)wormhole.physics.ubc.ca spake thusly:
> if ! [ "$line" = "$name" ]; then
> would do what you seem to want, although I do not know what =~ means.

Regex match. Another bashism (also a zshism). POSIX shells can do the
same thing via

if expr "$line" : "$name" >/dev/null; then
...
fi

(non-extended regexps only, always anchored as if started with ^).

If you need to use an extended regexp, use a pipe to grep -E and redirect
its output away to /dev/null (GNU grep has -q to do that, but if you're
trying to be portable you can't rely on it).
From: Chris F.A. Johnson on
On 2010-03-12, Folderol wrote:
> The script below works perfectly in bash, but if I try to run it on a
> system with dash I get the following error:
>
> Start_Midisport.sh: 21: [[: not found

Dash is a very basic POSIX shell. [[ ... ]] is not part of the
POSIX shell.

> Can anyone suggest what I should do to get it to work equally well in
> either shell?
>
>
> #!/bin/bash
>
> # echo's can be removed -just for testing
>
> name="MidiSport"
> lsusb | cat | while read line

Why do you have 'cat' in there?

> do
> if [[ "$line" =~ "$name" ]]

To test whether one string contains another, use case:

case $line in
*"$name"*) # Do whatever
;;
*) ;; # Do something else (or nothing)
esac

> then
> echo $line
> result=${line#'Bus '}
> busnumber=${result%' Device'*}
> result=${result#*'Device '}

You don't need the single quotes.

> devicenumber=${result%': ID'*}
> echo $busnumber
> echo $devicenumber
> result="sudo fxload -I /usr/local/share/usb/maudio/MidiSport2x2.ihx -D /dev/bus/usb/"$busnumber"/"$devicenumber
> echo $result
> exec $result
> fi
> done
> echo
>
>


--
Chris F.A. Johnson <http://cfajohnson.com>
Author: =======================
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
From: Richard Kettlewell on
Nix <nix-razor-pit(a)esperi.org.uk> writes:
> On 12 Mar 2010, Richard Kettlewell told this:
>> unruh <unruh(a)wormhole.physics.ubc.ca> writes:

>>> [[ is an internal command in bash. I guess it is not in dash.
>>> complain to the writers of dash.
>>
>> It's a Bashism, i.e. not a standard (in the POSIX sense) shell feature.
>
> Actually it's a kshism carried over into bash. (But you knew that.)

ksh is for legacy implementations l-)

--
http://www.greenend.org.uk/rjk/
From: Mark Hobley on
Nix <nix-razor-pit(a)esperi.org.uk> wrote:

>> It's a Bashism, i.e. not a standard (in the POSIX sense) shell feature.
>
> Actually it's a kshism carried over into bash. (But you knew that.)

Some of use the terms differently, but I would interpret a bashism as being
any syntax element that is not supported in the System V Unix shell. So a
kshism may also be called a bashism.

Mark.

--
Mark Hobley
Linux User: #370818 http://markhobley.yi.org/