RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1262847 - typeset -u/-l not working on values assigned before calling typeset
Summary: typeset -u/-l not working on values assigned before calling typeset
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: bash
Version: 7.1
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Ondrej Oprala
QA Contact: BaseOS QE - Apps
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2015-09-14 13:28 UTC by Martin Kyral
Modified: 2016-02-01 02:10 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2015-09-15 06:33:17 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

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."


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