LinuxQuestions.org
Register a domain and help support LQ
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, 02:41 AM   #1
Paulo2
Member
 
Registered: Aug 2012
Distribution: Slackware current(32) (started with 13.37(32))
Posts: 151

Rep: Reputation: 30
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, 03:09 AM   #2
Didier Spaier
Senior Member
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slackware{,64}-{14.1,current} on a Lenovo Thinkpad T61 6457-4XG
Posts: 4,644

Rep: Reputation: 1231Reputation: 1231Reputation: 1231Reputation: 1231Reputation: 1231Reputation: 1231Reputation: 1231Reputation: 1231Reputation: 1231
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 03:11 AM.
 
Old 04-27-2014, 10:07 AM   #3
Didier Spaier
Senior Member
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slackware{,64}-{14.1,current} on a Lenovo Thinkpad T61 6457-4XG
Posts: 4,644

Rep: Reputation: 1231Reputation: 1231Reputation: 1231Reputation: 1231Reputation: 1231Reputation: 1231Reputation: 1231Reputation: 1231Reputation: 1231
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 10:09 AM.
 
Old 04-27-2014, 11:15 AM   #4
fskmh
Member
 
Registered: Jun 2002
Location: South Africa
Distribution: Slackware64-current multilib
Posts: 236

Rep: Reputation: 55
@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, 12:00 PM   #5
Paulo2
Member
 
Registered: Aug 2012
Distribution: Slackware current(32) (started with 13.37(32))
Posts: 151

Original Poster
Rep: Reputation: 30
@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 04:27 PM. Reason: edited to indicate bash versions
 
Old 04-27-2014, 12:16 PM   #6
Paulo2
Member
 
Registered: Aug 2012
Distribution: Slackware current(32) (started with 13.37(32))
Posts: 151

Original Poster
Rep: Reputation: 30
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, 12:20 PM   #7
fskmh
Member
 
Registered: Jun 2002
Location: South Africa
Distribution: Slackware64-current multilib
Posts: 236

Rep: Reputation: 55
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, 12:33 PM   #8
fskmh
Member
 
Registered: Jun 2002
Location: South Africa
Distribution: Slackware64-current multilib
Posts: 236

Rep: Reputation: 55
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 12:34 PM.
 
Old 04-27-2014, 04:24 PM   #9
Paulo2
Member
 
Registered: Aug 2012
Distribution: Slackware current(32) (started with 13.37(32))
Posts: 151

Original Poster
Rep: Reputation: 30
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 2 03-24-2010 03:26 PM
variable expansion in bash coolhandluke1 Programming 4 01-09-2008 04:45 PM
Variable expansion in BASH champak Programming 5 11-26-2007 03:44 AM
!command expansion in csh vs. bash jhwilliams Linux - Software 9 08-27-2007 06:04 PM
Bash variables expansion olaola Linux - Newbie 4 10-16-2006 12:45 PM


All times are GMT -5. The time now is 04:37 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration