Bug 1262847 - typeset -u/-l not working on values assigned before calling typeset
typeset -u/-l not working on values assigned before calling typeset
Status: CLOSED NOTABUG
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: bash (Show other bugs)
7.1
Unspecified Unspecified
unspecified Severity unspecified
: rc
: ---
Assigned To: Ondrej Oprala
BaseOS QE - Apps
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2015-09-14 09:28 EDT by Martin Kyral
Modified: 2016-01-31 21:10 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2015-09-15 02:33:17 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Martin Kyral 2015-09-14 09:28:52 EDT
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 02:33:17 EDT
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."

Note You need to log in before you can comment on or make changes to this bug.