bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Strange Problem with 'test' or '['


From: Bytec GmbH - Helmut Koeberle
Subject: Strange Problem with 'test' or '['
Date: Wed, 23 Dec 2015 11:26:51 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130614 Thunderbird/17.0.6

Hello list,

i have a strange problem in bash with the test command.

Here is my simple bash script 'tst' that checks wether the first char of
an argument is a slash.
If the first char of the argument is a special char like '(' then it
works if there is one expression,
but not with multiple expressions.

Test script 'tst':

#!/bin/bash

set -x
h="$1"

if [ "${h:0:1}" = "/" ]; then echo slash; fi
if [ "true" = "true" -a "${h:0:1}" = "/" ]; then echo slash; fi


Results OK:
# ./tst /path

+ h=/path
+ '[' / = / ']'
+ echo slash
slash
+ '[' true = true -a / = / ']'
+ echo slash
slash


Results wrong:
# ./tst '(nopath)'

+ h='(nopath)'
+ '[' '(' = / ']'
+ '[' true = true -a '(' = / ']'
./tst: Zeile 7: [: `)' erwartet, / gefunden.

Seems to be a bug?

Kind regards
Helmut

-- 
Helmut Koeberle                         Tel. : +49-(0)7541-585-1005
Senior System Engineer                  Fax  : +49-(0)7541-585-2005

BYTEC GmbH                              mailto:helmut.koeberle@bytec.eu
Hermann-Metzger-Str.7                   http://www.bytec.eu
88045 Friedrichshafen

Geschäftsführer Dipl.-Ing. Matthias Bodry
Amtsgericht Ulm HRB 630959




reply via email to

[Prev in Thread] Current Thread [Next in Thread]