- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: scripting question
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
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
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
тАО01-06-2004 09:15 PM
тАО01-06-2004 09:15 PM
How can I put argument as variable in script? Such as:
If first argument to a script is "Arg1". If I do
x=1
echo $($x)
Can I get "Arg1" to print out? I know this is not the correct way to do. Anyone can point out the right way? Thanks.
regards,
tenghin
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-06-2004 09:21 PM
тАО01-06-2004 09:21 PM
Re: scripting question
x=$1
echo $($x)
Regards,
Bernhard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-06-2004 09:25 PM
тАО01-06-2004 09:25 PM
Re: scripting question
You can capture them as $1, $2 etc. You can use them as any other variable.
echo $1
HTH,
Umapathy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-06-2004 09:32 PM
тАО01-06-2004 09:32 PM
Re: scripting question
Thanks for the reply. The reason I want to make the argument as variable is because sometime the position of argument can change, may be first argument, may be second. So I don't think your suggestion can work. Do you have other suggestion ?
regards,
tenghin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-06-2004 09:37 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-06-2004 09:41 PM
тАО01-06-2004 09:41 PM
Re: scripting question
At some point you have to identify what that incoming argument means. At that same point you can assign them to your variable of choice.
I dont find any problem here.
HTH,
Umapathy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-06-2004 09:42 PM
тАО01-06-2004 09:42 PM
Re: scripting question
Thanks a lot. That is just what I want.
Umapathy,
Thanks for you reply also.
Thanks guys!!
regards,
tenghin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-06-2004 09:46 PM
тАО01-06-2004 09:46 PM
Re: scripting question
so I guess you want something like
./script -1 arg1 -2 arg2
would work exactly like
./script -2 arg2 -1 arg1
???
then you would use a case statement and use shift for each $1 to read each script argument sequentially and set variables according to whether -1 -2 etc have been found until you have gone through the whole command line.
Regards,
Bernhard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-06-2004 09:56 PM
тАО01-06-2004 09:56 PM
Re: scripting question
Actually what I want is assign the second last argument to a variable, such as :
x=$#
y=`expr $x - 1`
h=`eval echo \${$y}`
echo $h
I can do "eval echo \${$y}" alone but cannot assign to variable h as above.Any idea anyone ?
regards,
tenghin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-06-2004 10:09 PM
тАО01-06-2004 10:09 PM
Re: scripting question
One way to do is to use the shift. Go on shifting till last but one.
HTH,
Umapathy