Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-29-2003, 02:38 PM   #1
LQ Newbie
Registered: Aug 2003
Posts: 26

Rep: Reputation: 15
Bash script renaming a variable

Is there a way in script to rename a variable to all lowercase. I know you can probably use an expression?
Old 09-29-2003, 02:51 PM   #2
Registered: Sep 2003
Location: Dallas, Tx, USA
Distribution: Red Hat, Gentoo, Libranet
Posts: 98

Rep: Reputation: 16
To the best of my knowledge, there is no way to rename a variable at all.

I'm assuming you want to change "PWD" to "pwd" or something along those lines.

You can very easily say "pwd=$PWD" and refer to $pwd throughout the rest of your script, but "$pwd" is always going to have the value it had when you ran the assignment statement.

If $PWD changes (say when you cd to another directory), $pwd is NOT going to follow it.

In the more general case, there is no way to cause a program/script to use a different variable name except by changing the source code (and recompiling if it's a binary).

You might want to post why you want to do this. Usually, when people want to do something impossible, what they want it FOR is pretty reasonable, that's just not the right way to do it.

Post the problem you were trying to solve by renaming a variable and the odds are medium good someone can suggest a workable alternative.

Good luck,

Old 09-29-2003, 08:48 PM   #3
LQ Newbie
Registered: Aug 2003
Posts: 26

Original Poster
Rep: Reputation: 15
renaming an input variable to lowercase

The problem i am having is when i have a script wich calls for an input from someone i want to automaticly change the text to lowecase. an example is below?

echo -r "What is the name for you file: "
read tmp

I want to change whatever is enter to lowercase.

Old 09-30-2003, 04:37 AM   #4
Registered: Jul 2003
Location: NL
Distribution: My own
Posts: 92

Rep: Reputation: 18
tmp_lcase=$(echo $tmp | tr A-Z a-z)


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
How to export environment variable from a bash script dimaash Linux - Newbie 20 08-09-2011 07:12 AM
sed doesn't accept $variable in bash script chii-chan Programming 6 05-28-2005 07:07 AM
Bash Script Passing variable to Function nutthick Programming 2 02-02-2005 05:15 AM
Bash script; command and args in variable. magjo813 Programming 2 02-16-2004 09:22 AM
bash script $n variable expansion cortez Programming 6 12-08-2003 04:03 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:22 AM.

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