HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Capture output of successful command in a shel...
Operating System - HP-UX
1834459
Members
2390
Online
110067
Solutions
Forums
Categories
Company
Local Language
back
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
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- 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
02-21-2003 05:19 AM
02-21-2003 05:19 AM
Capture output of successful command in a shell.
Hello All,
How to get the results of a sucessfull command into a variable?
I know the way to get the output of an "unsuccessful" command into a variable, from the discussion today initiated by Sean on this forum.
For Example,
I want to grab the output of sleep when it is sucessful, to get the process id of the process:
I execute the following command:
$ sleep 10 &
[1] 13482
I want to capture the output containing the process id.
Regards,
Shashi
How to get the results of a sucessfull command into a variable?
I know the way to get the output of an "unsuccessful" command into a variable, from the discussion today initiated by Sean on this forum.
For Example,
I want to grab the output of sleep when it is sucessful, to get the process id of the process:
I execute the following command:
$ sleep 10 &
[1] 13482
I want to capture the output containing the process id.
Regards,
Shashi
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2003 05:25 AM
02-21-2003 05:25 AM
Re: Capture output of successful command in a shell.
You can't 'capture' that output.
However, the process id of the last background command invoked by the shell (13482) in your example is held in the $! variable.
Thus:
sleep 10&
CHILD=${!}
$CHILD will contain the relevant PID.
Regards,
John
However, the process id of the last background command invoked by the shell (13482) in your example is held in the $! variable.
Thus:
sleep 10&
CHILD=${!}
$CHILD will contain the relevant PID.
Regards,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2003 05:31 AM
02-21-2003 05:31 AM
Re: Capture output of successful command in a shell.
Hi
Try this
#(sleep 10 ;echo $? > output.txt ) &
Chris
Try this
#(sleep 10 ;echo $? > output.txt ) &
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2003 06:17 AM
02-21-2003 06:17 AM
Re: Capture output of successful command in a shell.
Hi Shashi,
I know it doesn't directly put the output into a variable, but you could use the script command:
script /tmp/output.txt
sleep 1 &
Ctrl-D
cat /tmp/output.txt
Script started on Fri Feb 21 14:16:14 2003
# sleep 1 &
[1] 18447
ln4p2714-64 #
script done on Fri Feb 21 14:16:21 2003
rgds, Robin
I know it doesn't directly put the output into a variable, but you could use the script command:
script /tmp/output.txt
sleep 1 &
Ctrl-D
cat /tmp/output.txt
Script started on Fri Feb 21 14:16:14 2003
# sleep 1 &
[1] 18447
ln4p2714-64 #
script done on Fri Feb 21 14:16:21 2003
rgds, Robin
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP