LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 04-27-2014, 01:41 AM   #1
Paulo2
Member
 
Registered: Aug 2012
Distribution: Slackware64 15.0 (started with 13.37). Testing -current in a spare partition.
Posts: 925

Rep: Reputation: 514Reputation: 514Reputation: 514Reputation: 514Reputation: 514Reputation: 514
Broken ${var~} expansion on Bash 4.3.11 ?


Hello friends, if I'm not mistaken, that expansion doesn't work anymore.
Is it intentional, maybe?
I searched with Google but didn't find anything related.

$ echo $BASH_VERSION
4.2.45(2)-release
$ a='the rolling stones'
$ echo ${a~}
The Rolling Stones

$ echo $BASH_VERSION
4.3.11(1)-release
$ a='the rolling stones'
$ echo ${a~}
The rolling stones
 
Old 04-27-2014, 02:09 AM   #2
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,048

Rep: Reputation: Disabled
Well, this case modification however provided is not listed among the parameter expansions in the manual for 4.2.37(2)-release that I'm using in Slackware 14.0, so that change is maybe just to make sure the features be in sync with the manual...

I tend to avoid these kinds of bashism anyway

Last edited by Didier Spaier; 04-27-2014 at 02:11 AM.
 
Old 04-27-2014, 09:07 AM   #3
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,048

Rep: Reputation: Disabled
Let's be a little more constructive:
Code:
bash-4.2$ a='the rolling stones'
bash-4.2$ for i in $a;do echo -n "${i^} ";done;echo
The Rolling Stones 
bash-4.2$
Removing the last white space is left to the reader.

Last edited by Didier Spaier; 04-27-2014 at 09:09 AM.
 
Old 04-27-2014, 10:15 AM   #4
fskmh
Member
 
Registered: Jun 2002
Location: South Africa
Distribution: Custom slackware64-current
Posts: 307

Rep: Reputation: 92
@Didier: There are a bunch of useful parameter expansions in Bash 4 that allow one to do conversions like that directly on a script variable, and I think this is what Paulo is really keen on. (Old farts like us will just have to grudgingly learn them. :-p)

@Paulo2: I can confirm the results you are getting. I have tried recompiling bash 4.3.11 after upgrading to readline-6.3 (in case that was somehow involved) and I have tried compiling it with --enable-casemod-attributes and --enable-casemod-expansions explicitly enabled but none of that helped. Setting bash 4.2 compatibility mode with "shopt -s compat42" doesn't seem to help either.
I have come to the conclusion that this is some kind of regression that should be reported to upstream.
 
Old 04-27-2014, 11:00 AM   #5
Paulo2
Member
 
Registered: Aug 2012
Distribution: Slackware64 15.0 (started with 13.37). Testing -current in a spare partition.
Posts: 925

Original Poster
Rep: Reputation: 514Reputation: 514Reputation: 514Reputation: 514Reputation: 514Reputation: 514
@Didier Spaier Yes, that expansion can do the same with little extra work

But ${var~} expanded with non blank separators too
bash 4.2.45(2)-release
$ a='the_rolling_stones'
$ echo ${a~}
The_Rolling_Stones

$ a='the.rolling.stones'
$ echo ${a~}
The.Rolling.Stones

$ a='the-rolling-stones'
$ echo ${a~}
The-Rolling-Stones


bash 4.3.11(1)-release
a='the_rolling_stones'
[[ "$a" =~ [^[:alnum:]] ]]
for var in $(tr $BASH_REMATCH ' ' <<<"$a");do
echo -n "${var^}$BASH_REMATCH"
done|sed 's/.$//';echo
The_Rolling_Stones

Will be more complicated with different separators I guess


I think Bash is taking the job with little editions, like
those with capitalization, or substitution and trimming,
things done with sed, cut, tr, etc...
Let's see on future releases what they got on 'testing' dir

One can use those expansions at home, but if the script
will be public, chances of incompatibility are very big.

@fskmh thanks for the testings, I didn't remember to test all those options.
Is that regression intentional? It will break someone's scripts around the world,
this is for sure.

Last edited by Paulo2; 04-27-2014 at 03:27 PM. Reason: edited to indicate bash versions
 
Old 04-27-2014, 11:16 AM   #6
Paulo2
Member
 
Registered: Aug 2012
Distribution: Slackware64 15.0 (started with 13.37). Testing -current in a spare partition.
Posts: 925

Original Poster
Rep: Reputation: 514Reputation: 514Reputation: 514Reputation: 514Reputation: 514Reputation: 514
Reading that page parameter expansions there's this
expansion with arrays, it expand all the elements

Quote:
Case modification: Arrays

For array expansion, the case modification applies to every expanded element, no matter if you expand an individual index or mass-expand the whole array using @ or * subscripts. Some examples:

Assume: array=(This is some Text)

echo "${array[@],}"
⇒ this is some text
echo "${array[@],,}"
⇒ this is some text
echo "${array[@]^}"
⇒ This Is Some Text
echo "${array[@]^^}"
⇒ THIS IS SOME TEXT
echo "${array[2]^^}"
⇒ TEXT
ps- Is the last example wrong?
 
Old 04-27-2014, 11:20 AM   #7
fskmh
Member
 
Registered: Jun 2002
Location: South Africa
Distribution: Custom slackware64-current
Posts: 307

Rep: Reputation: 92
Quote:
Originally Posted by Paulo2 View Post
@fskmh thanks for the testings, I didn't remember to test all those options.
Is that regression intentional? It will break someone's scripts around the world,
this is for sure.
That is a question that is best directed at the Bash devs IMO.

One reason why I suspect a regression is that the reverse-case-for-all expansion still works:
Code:
echo $BASH_VERSION; a='the rolling stones'; echo ${a~}; echo ${a~~}
4.3.11(1)-release
The rolling stones
THE ROLLING STONES
This might help you in the meantime though:
Code:
echo $BASH_VERSION; unset a; a=(the rolling stones); echo ${a[@]^}
4.3.11(1)-release
The Rolling Stones
 
Old 04-27-2014, 11:33 AM   #8
fskmh
Member
 
Registered: Jun 2002
Location: South Africa
Distribution: Custom slackware64-current
Posts: 307

Rep: Reputation: 92
Quote:
Originally Posted by Paulo2 View Post
ps- Is the last example wrong?
I think ${BLAH[@]^^} does the same for an array as ${BLAH~~} does for a regular variable.

It seems a=(blah) is the same as declaring an array with "declare -a".
Code:
echo $BASH_VERSION; unset a; a=(the rolling stones); echo ${a~}; echo ${a[@]~}; echo ${a[@]^}
4.3.11(1)-release
The
The Rolling Stones
The Rolling Stones

Last edited by fskmh; 04-27-2014 at 11:34 AM.
 
Old 04-27-2014, 03:24 PM   #9
Paulo2
Member
 
Registered: Aug 2012
Distribution: Slackware64 15.0 (started with 13.37). Testing -current in a spare partition.
Posts: 925

Original Poster
Rep: Reputation: 514Reputation: 514Reputation: 514Reputation: 514Reputation: 514Reputation: 514
Quote:
This might help you in the meantime though:
Code:

echo $BASH_VERSION; unset a; a=(the rolling stones); echo ${a[@]^}
4.3.11(1)-release
The Rolling Stones
I was reading about expanding arrays, very useful.


Quote:
Quote:
Originally Posted by Paulo2 View Post
ps- Is the last example wrong?
I mean that I think the last example is wrong

array=(This is some Text)

echo "${array[2]^^}"
⇒ TEXT

The element with index 2 is 'some'
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash - brace expansion using variable student04 Linux - Software 3 03-07-2017 05:04 AM
variable expansion in bash coolhandluke1 Programming 4 01-09-2008 03:45 PM
Variable expansion in BASH champak Programming 5 11-26-2007 02:44 AM
!command expansion in csh vs. bash jhwilliams Linux - Software 9 08-27-2007 05:04 PM
Bash variables expansion olaola Linux - Newbie 4 10-16-2006 11:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 08:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration