LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 07-29-2003, 04:07 AM   #1
x2000koh
Member
 
Registered: Jul 2002
Location: singapore
Distribution: red had 7.2
Posts: 109

Rep: Reputation: 15
variable to string


Hi ! All
Trying to pick up shell script. When I do :

mis="123"
echo $mis

It return "123"

Now, if I want to return the the result "mis" instead of value "123". How can I do that ?

I am beginner, appreciate all the experts here to help.

Regards,
x2000koh
 
Old 07-29-2003, 05:58 AM   #2
DIYLinux
Member
 
Registered: Jul 2003
Location: NL
Distribution: My own
Posts: 92

Rep: Reputation: 17
Simple: you have to escape (take away special meaning) the quotes.

XXX=\"xxx\" echo $XXX

Gives "xxx"

You may also use single quotes. Everything inside is taken literally, without any special meaning, ie XXX=' "xxx" '

If you want to surround text with single quotes, you have to use the backslash escape method.

Recommended reading:

bash(1) # that is the man page in section 1. Try man bash
bash info documentation
Advanced Bash Scripting HOWTO (start out simple. See www.tldp.org)
 
Old 07-29-2003, 09:16 AM   #3
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Rep: Reputation: 31
Re: variable to string

Quote:
Originally posted by x2000koh
Hi ! All
Trying to pick up shell script. When I do :

mis="123"
echo $mis

It return "123"

Now, if I want to return the the result "mis" instead of value "123". How can I do that ?

I am beginner, appreciate all the experts here to help.

Regards,
x2000koh
You want the name of the variable? Just:

Code:
echo mis
You already KNOW the name of the variable, as you chose it when you coded it ... I don't see how this is very useful.
 
Old 07-29-2003, 09:19 PM   #4
x2000koh
Member
 
Registered: Jul 2002
Location: singapore
Distribution: red had 7.2
Posts: 109

Original Poster
Rep: Reputation: 15
strike
Thanks for reply ! to let you know the full picture of what I am going to do.

1) I have written a script to evaluate the user group (GID). It only return the GID in number. But I want it to return a group name.

My script is as follow.

addlink.sh
-------------
group=$(id -g)
echo $group


when I run the above it return "511". let say GID 511 is mis group. How can I convert the 511 to show mis. (can I echo $511 ?)

2) softlink base on department

if GID is mis
ln -s /home/dept/mis mis
end if

3) calling a script
How can I call another script from my existing program ? Which command to use ?

I want the .bash_profile to call the addlink.sh when user login.

The addlink.sh is located at /home/maple
The .bash_profile is located at /home/maple/$USER

appreciate your help.

x2000koh
 
Old 07-30-2003, 03:23 AM   #5
DIYLinux
Member
 
Registered: Jul 2003
Location: NL
Distribution: My own
Posts: 92

Rep: Reputation: 17
To lookup a group, based on numwerical GID, use id -gn. (or grep if youre feeling masochistic)

To call another script, see my reply in the other thread you started
 
  


Reply


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
reading a char string of variable size in C introuble Programming 3 05-08-2005 02:07 PM
Print a part of variable/string p0tw0r Linux - Newbie 1 04-07-2005 03:49 PM
Perl variable string search ugenn Programming 1 05-07-2004 09:19 PM
Assigning a string to a variable (not a pointer, not a array) JStew Programming 3 11-18-2002 09:13 AM
Getting a variable name based on a string. jtshaw Programming 7 10-08-2002 03:06 PM


All times are GMT -5. The time now is 04:42 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration