LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   variable to string (https://www.linuxquestions.org/questions/programming-9/variable-to-string-76848/)

x2000koh 07-29-2003 03:07 AM

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

DIYLinux 07-29-2003 04:58 AM

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)

Strike 07-29-2003 08:16 AM

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.

x2000koh 07-29-2003 08:19 PM

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

DIYLinux 07-30-2003 02:23 AM

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


All times are GMT -5. The time now is 04:17 PM.