- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to pass a name through a variable.
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2003 04:03 AM
11-06-2003 04:03 AM
I'm trying to pass a name through a variable for example.
NAME=Robert; export NAME
If I do this from the command line is not a problem, but if I try to pass this in a script, I get the following message. "The parameter is not set" when I recall the variable with the echo command "echo $NAME".
This should be simple, but for some reason I can not make it work. If you can help me, I will really appreciated because I need to pass a few. I will give points to the answers.
Thanks in advance,
RT.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2003 04:09 AM
11-06-2003 04:09 AM
Re: How to pass a name through a variable.
can you post us, how you do it now?
greetings,
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2003 04:09 AM
11-06-2003 04:09 AM
Re: How to pass a name through a variable.
newscriptname $NAME
The value in $NAME will be available to the new script as $1
It can then be transferred to any variable you need as follows:
NAME=$1
export NAME
The script will then be able to use it any way it needs.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2003 04:09 AM
11-06-2003 04:09 AM
Re: How to pass a name through a variable.
export NAME=Robert
echo $NAME
Best regards,
dl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2003 04:12 AM
11-06-2003 04:12 AM
Solutionexport NAME=Robert BUT that is still not going to do what I think you are trying to do. You seem to be trying to export a variable in a child process to a parent. That will never work because the parent never inherits from the child.
What you can do is pass the data through a temporary file or use the "." (dot) to include the script so that it actually runs in the foreground.
e.g.
export NAME=Robert
save this (along with anything else) in a file (e.g. /usr/local/bin/myscript.sh)
Now from your main script simply
. /usr/local/bin/myscript.sh
That will fix you BUT myscript.sh must not contain an exit or return statement because that will have the effect of exiting the foreground process (since they are now one and the same).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2003 04:19 AM
11-06-2003 04:19 AM
Re: How to pass a name through a variable.
When you are running your script, the variable gets defined in a subshell, which is then not available in the original shell.
If you source the script, it will get run in the current shell, and the variable will be defined.
for example, the script I have named t, defines name=fred and exports it.
# cat t
name=fred
export name
#
from the command line I define name=john, export it, then echo it.
# name=john
# export name
# echo $name
john
#
If I run the script in a subshell, name in the current shell remains = john.
# ./t
# echo $name
john
#
If I run the script in the current shell, name will be changed.
# . ./t
# echo $name
fred
#
- John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2003 04:21 AM
11-06-2003 04:21 AM
Re: How to pass a name through a variable.
You can put all the variables inside a script that you want to export and source the same to the shell. It will be available for that shell. For that
. ./<script_having_vars>.sh
You can pass arguments to a shell script also which will be assigned to $1 ... $n depending on the number of args you pass.
HTH,
Umapathy