- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- KSH cmd var problem?
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
06-14-2002 07:23 AM
06-14-2002 07:23 AM
Come across this interesting situation, which no-one at my company is able to help with, so hoping one of you nice people can help...
From a KSH command line, the following command works as expected, output goes to the screen.
echo "This is a test" >&1
However, if you re-write it as follows, then the results are not the same, infact a file named '&1' is created.
X="&1"; echo "This is a test" >${X}
Why doesn't it work, and is there some way to make it work?
Cheers in advance,
Robin Abecasis
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2002 07:25 AM
06-14-2002 07:25 AM
Re: KSH cmd var problem?
You would need to supply an "eval" somewhere to make it work.
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2002 07:29 AM
06-14-2002 07:29 AM
Re: KSH cmd var problem?
X="1"; echo "This is a test" >&${X}
There is something specific about the behavior of the varaible in this position. I believe that the > and & characters form a token of sorts - the same kind of token that > and $ don't.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2002 07:29 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2002 07:35 AM
06-14-2002 07:35 AM
Re: KSH cmd var problem?
Cheers,
Robin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2002 07:56 AM
06-14-2002 07:56 AM
Re: KSH cmd var problem?
The shell (ksh, sh) interprets commands in a well-defined sequence:
Parse the line
Verbose trace
Parameter substitution
Command substitution
I/O redirection
IFS processing
Filename expansion
Execution trace
Run the command
You might think that because I/O redirection comes after parameter substitution, this would make your original statement work, but the key is that '&' is a special character which the shell marks during the initial line parse. This happens before the parameter substitution, so by the time you get to I/O redirection the '&1' is just another string to teh shell, not a stream file descriptor.
This ends my uncrontrollable pedantism for today. Please return to you rregularly scheduled lives.