- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Passing a string containing the name of 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
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
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
07-12-2018 06:47 AM - edited 07-12-2018 07:19 AM
07-12-2018 06:47 AM - edited 07-12-2018 07:19 AM
Passing a string containing the name of a variable to a script
Hi there,
After hours of attempts I think that there is no solution to this tricky problem ! really no ideas !
here is my script myscript.ksh
#I need to redefine AA inside the script itself
cmd=$1
AA="Orange"
echo $cmd
output of the command below
AA=""
./myscript.ksh "This is the new value ${AA}"
should be:
This is the new value: Orange
But because of the evalutation of the parameter result is:
This is the new value:
How to do the trick !??
kind regards,
Den.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2018 09:01 AM - edited 07-12-2018 09:02 AM
07-12-2018 09:01 AM - edited 07-12-2018 09:02 AM
Re: Passing a string containing the name of a variable to a script
Are you trying to set the command line parameter $1?
If so, look at the exec command that can restart your script with new values.
Or the eval command to take any string and process it as a shell command.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2018 11:30 AM
07-12-2018 11:30 AM
Re: Passing a string containing the name of a variable to a script
> How to do the trick !??
> ./myscript.ksh "This is the new value ${AA}"
With quotation marks ("), the (interactive) shell evaluates "${AA}"
immediately, and the script never sees "AA". Usig apostrophes (') would
help. Consider:
pro3$ AA=fred
pro3$ cat script1.sh
#!/bin/sh
cmd=$1
AA='Orange'
echo "$cmd"
eval "echo \"$cmd\""
pro3$ ./script1.sh "New value: ${AA}"
New value: fred
New value: fred
pro3$ ./script1.sh 'New value: ${AA}'
New value: ${AA}
New value: Orange