Bug 1262847

Summary: typeset -u/-l not working on values assigned before calling typeset
Product: Red Hat Enterprise Linux 7 Reporter: Martin Kyral <mkyral>
Component: bashAssignee: Ondrej Oprala <ooprala>
Status: CLOSED NOTABUG QA Contact: BaseOS QE - Apps <qe-baseos-apps>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.1CC: ovasik
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-09-15 06:33:17 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Martin Kyral 2015-09-14 13:28:52 UTC
Description of problem:
typeset has options -u and -l to uppercase / lowercase all characters in the given variable. While this works if there is value assigned to the variable within the typeset call, it fails to do so if the value has been assigned to the variable before calling typeset upon it. See the demo.

test.sh:

#!/bin/bash

echo "value assigned via typeset"

typeset -u test_u=uppercase
typeset -xu test_xu=uppercase
typeset -txu test_txu=uppercase

echo "uppercased: ${test_u}  ${test_xu}   ${test_txu}"

unset test_u
unset test_xu
unset test_txu

typeset -l test_u=LOWERCASE
typeset -xl test_xu=LOWERCASE
typeset -txl test_txu=LOWERCASE

echo "lowercased: ${test_u}  ${test_xu}   ${test_txu}"

unset test_u
unset test_xu
unset test_txu

test_u=uppercase
typeset -u test_u
test_xu=uppercase
typeset -xu test_xu
test_txu=uppercase
typeset -txu test_txu

echo "value assigned before calling typeset"

echo "uppercased: ${test_u}  ${test_xu}   ${test_txu}"

unset test_u
unset test_xu
unset test_txu

test_u=LOWERCASE
typeset -u test_u
test_xu=LOWERCASE
typeset -xu test_xu
test_txu=LOWERCASE
typeset -txu test_txu

echo "lowercased: ${test_u}  ${test_xu}   ${test_txu}"

unset test_u
unset test_xu
unset test_txu

[0 root@qeos-51 ~]# bash test.sh
value assigned via typeset
uppercased: UPPERCASE  UPPERCASE   UPPERCASE
lowercased: lowercase  lowercase   lowercase
value assigned before calling typeset
uppercased: uppercase  uppercase   uppercase
lowercased: LOWERCASE  LOWERCASE   LOWERCASE


Version-Release number of selected component (if applicable):
bash-4.2.46-19.el7

How reproducible:
Always


Steps to Reproduce:
1. see description
2.
3.

Actual results:


Expected results:


Additional info:

Comment 1 Ondrej Oprala 2015-09-15 06:33:17 UTC
Hi Martin,
this is the way it's supposed to work. The conversion is done upon assignment, not upon expansion (as zsh does, for example), so existing values are not affected... or as the manpage says:
"When the variable is assigned a value, all lower-case characters are converted to upper-case."