LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 09-29-2003, 02:38 PM   #1
zael
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
clacour
Member
 
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,

CHL
 
Old 09-29-2003, 08:48 PM   #3
zael
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.

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

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


Reply



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:44 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration