j'ai des variables qui contiennent des espaces, et lorsque ceux-ci sont à la fin ils sont toujours supprimés, ce que je ne souhaite pas.
Ainsi:
TOTO="TOTO " expr length $TOTO 4
Et non 5.
Comment conserver cet espace de fin pour que la longueur de chaine soit à 5 ?
expr length "$TOTO"
Stephane Chazelas
On 7 Oct 2005 01:14:32 -0700, wrote:
Bonjour,
j'ai des variables qui contiennent des espaces, et lorsque ceux-ci sont à la fin ils sont toujours supprimés, ce que je ne souhaite pas.
Ainsi:
TOTO="TOTO " expr length $TOTO 4
Et non 5.
Comment conserver cet espace de fin pour que la longueur de chaine soit à 5 ? [...]
Leaving a variable unquoted when in a list context (here the arguments of a command) has a very special meaning to the shell. You should never do that unless you know what you are doing and why. Also note that "length" is not a standard operator to expr.
expr "X$TOTO" : '.*' - 1 || :
The "X" is because "expr" has a badly designed syntax. If $TOTO were any known operator to "expr", "expr" would fail without "X". Fortunately (so far) expr has no operator beginning with a "X".
"..." is to prevent the shell doing word splitting (which resulted in the removal of spaces in your case) and filename generation. The '...' is because "*" is a special character to the shell. "|| :" is because "expr" would return a "false" exit status if $TOTO is empty while there's no reason it should.
-- Stephane
On 7 Oct 2005 01:14:32 -0700, joulio@gmail.com wrote:
Bonjour,
j'ai des variables qui contiennent des espaces, et lorsque ceux-ci sont
à la fin ils sont toujours supprimés, ce que je ne souhaite pas.
Ainsi:
TOTO="TOTO "
expr length $TOTO
4
Et non 5.
Comment conserver cet espace de fin pour que la longueur de chaine soit
à 5 ?
[...]
Leaving a variable unquoted when in a list context (here the
arguments of a command) has a very special meaning to the shell.
You should never do that unless you know what you are doing and
why. Also note that "length" is not a standard operator to expr.
expr "X$TOTO" : '.*' - 1 || :
The "X" is because "expr" has a badly designed syntax. If $TOTO
were any known operator to "expr", "expr" would fail without
"X". Fortunately (so far) expr has no operator beginning with a
"X".
"..." is to prevent the shell doing word splitting (which
resulted in the removal of spaces in your case) and filename
generation. The '...' is because "*" is a special character to
the shell. "|| :" is because "expr" would return a "false" exit
status if $TOTO is empty while there's no reason it should.
j'ai des variables qui contiennent des espaces, et lorsque ceux-ci sont à la fin ils sont toujours supprimés, ce que je ne souhaite pas.
Ainsi:
TOTO="TOTO " expr length $TOTO 4
Et non 5.
Comment conserver cet espace de fin pour que la longueur de chaine soit à 5 ? [...]
Leaving a variable unquoted when in a list context (here the arguments of a command) has a very special meaning to the shell. You should never do that unless you know what you are doing and why. Also note that "length" is not a standard operator to expr.
expr "X$TOTO" : '.*' - 1 || :
The "X" is because "expr" has a badly designed syntax. If $TOTO were any known operator to "expr", "expr" would fail without "X". Fortunately (so far) expr has no operator beginning with a "X".
"..." is to prevent the shell doing word splitting (which resulted in the removal of spaces in your case) and filename generation. The '...' is because "*" is a special character to the shell. "|| :" is because "expr" would return a "false" exit status if $TOTO is empty while there's no reason it should.
-- Stephane
Stephane Chazelas
On 07 Oct 2005 08:28:21 GMT, Stephane Chazelas wrote: [...]
expr length $TOTO 4
Et non 5.
Comment conserver cet espace de fin pour que la longueur de chaine soit à 5 ? [...]
Leaving a variable unquoted when in a list context (here the arguments of a command) has a very special meaning to the shell. You should never do that unless you know what you are doing and why. Also note that "length" is not a standard operator to expr.
expr "X$TOTO" : '.*' - 1 || : [...]
hrummm, j'imagine que ca devait arriver. Ca m'apprendra a poster dans les news avant mon premier café. Sur le point de vue technique, sinon du langage, je pense que c'est correct, sinon.
Désolé, Stephane
On 07 Oct 2005 08:28:21 GMT, Stephane Chazelas wrote:
[...]
expr length $TOTO
4
Et non 5.
Comment conserver cet espace de fin pour que la longueur de chaine soit
à 5 ?
[...]
Leaving a variable unquoted when in a list context (here the
arguments of a command) has a very special meaning to the shell.
You should never do that unless you know what you are doing and
why. Also note that "length" is not a standard operator to expr.
expr "X$TOTO" : '.*' - 1 || :
[...]
hrummm, j'imagine que ca devait arriver. Ca m'apprendra a poster
dans les news avant mon premier café. Sur le point de vue
technique, sinon du langage, je pense que c'est correct, sinon.
On 07 Oct 2005 08:28:21 GMT, Stephane Chazelas wrote: [...]
expr length $TOTO 4
Et non 5.
Comment conserver cet espace de fin pour que la longueur de chaine soit à 5 ? [...]
Leaving a variable unquoted when in a list context (here the arguments of a command) has a very special meaning to the shell. You should never do that unless you know what you are doing and why. Also note that "length" is not a standard operator to expr.
expr "X$TOTO" : '.*' - 1 || : [...]
hrummm, j'imagine que ca devait arriver. Ca m'apprendra a poster dans les news avant mon premier café. Sur le point de vue technique, sinon du langage, je pense que c'est correct, sinon.