[Top][All Lists]

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

Wrong variable expansion inside quotation marks

From: Reuti
Subject: Wrong variable expansion inside quotation marks
Date: Wed, 13 Feb 2008 12:21:38 +0100


I have one system with:

address@hidden:~> bash --version
GNU bash, version 3.00.16(1)-release (i586-suse-linux)
Copyright (C) 2004 Free Software Foundation, Inc.

address@hidden:~> hallo=hallo
address@hidden:~> rr=r
address@hidden:~> tt="${rr:0:${#rr}-1}$hallo"
address@hidden:~> echo ${#tt}

This is what I expect. But in an newer bash:

address@hidden:~$ bash --version
GNU bash, version 3.1.17(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.

address@hidden:~$ hallo=hallo
address@hidden:~$ rr=r
address@hidden:~$ tt="${rr:0:${#rr}-1}$hallo"
address@hidden:~$ echo ${#tt}

There is suddenly a 6th illegal character generated (in the original routine its purpose was to remove the last character of $rr (which is als at least one character long). But only if rr is one character long - if it's longer all is fine again.

I circumvent the problem for now by removing the quotation marks:

address@hidden:~$ tt=${rr:0:${#rr}-1}$hallo
address@hidden:~$ echo ${#tt}

-- Reuti

reply via email to

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