- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Using variable to execute command...
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
10-17-2002 07:30 AM
10-17-2002 07:30 AM
I want to do something like that :
CMD="cat /etc/inittab > /tmp/inittab"
$CMD
The pb is that the ">" is not correctly parsed ! :-(
The $CMD is send to a function executing it and testing its return code.
Does anybody know the answer ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2002 07:32 AM
10-17-2002 07:32 AM
Re: Using variable to execute command...
Try escaping it with
CMD="cat /etc/inittab \> /tmp/inittab"
$CMD
Hope this helps
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2002 07:36 AM
10-17-2002 07:36 AM
Re: Using variable to execute command...
eval "${CMD}"
That should fix you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2002 07:39 AM
10-17-2002 07:39 AM
Re: Using variable to execute command...
CMD=$(cat /etc/inittab > /tmp/inittab)
$CMD
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2002 08:28 AM
10-17-2002 08:28 AM
Re: Using variable to execute command...
Why not create them as functions.
cat_inittab ()
{
cat /etc/inittab > /tmp/inittab
}
then simply call the function.
# call function.
cat_inittab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2002 12:20 PM
10-17-2002 12:20 PM
SolutionA "3" will show your respect towards others for their time if they couldn't solve your problem. All the answers you got so far are "something" like what you said.
What you are executing is a command and it is to be treated with the same respect. So, you will need to do any of the following.
1. Declare it as a function and call the function.
2. Do exactly what you want to do but execute the variable with "eval" call.
3. Put it in command substitution syntax so that the shell will understand that it is a command.
4. Make it as an alias and run the alias.
alias CMD="cat /etc/inittab > /tmp/iniitab"
CMD
The solution closest to what you need is command substitution. If you don't want to use $ substitution, I guess you can replace double quotes with backticks (the key associated with ~).
CMD=`cat /etc/inittab > /tmp/inittab`
$CMD
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2002 11:51 PM
10-17-2002 11:51 PM
Re: Using variable to execute command...
It was not a lack of respect, sorry if it has been missunderstood.
I also want to apologize A. Clay Stephenson because his solution works properly (I did a mistake when writing the command).
Thanx for all.
Sebastien.