- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- control (enable/disable) redirect to /dev/null
Operating System - HP-UX
1748124
Members
3224
Online
108758
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
Discussions
Discussions
Forums
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
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
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
тАО04-02-2009 03:14 AM
тАО04-02-2009 03:14 AM
hello,
how can i control (enable/disable) redirect to /dev/null in script ? for example, when a variable DEBUG hasn't value "Y", output redirect to /dev/null. if value "Y", i should see the output. i need this for disable/enable oracle "sqlplus" output in a ksh script.
i read forum entry "about redirect"
http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=858713
and find two solutions :
1. script : based on forum entry:
DEBUG=""
if [ "${DEBUG}" = "Y" ]
then
OUTPUTDEVNULL="" # i should see the output
else
OUTPUTDEVNULL="/dev/null"
fi
echo "test" > ${OUTPUTDEVNULL} 2>&
2. script : example with exec
DEBUG=""
if [ "${DEBUG}" = "Y" ]
then
exec 3>&2 # i should see the output
else
exec 3>/dev/null
fi
echo "test" >&3
exec 3>&- # close the file descriptor
what i the best solution ? other way to solve this ?
regards
how can i control (enable/disable) redirect to /dev/null in script ? for example, when a variable DEBUG hasn't value "Y", output redirect to /dev/null. if value "Y", i should see the output. i need this for disable/enable oracle "sqlplus" output in a ksh script.
i read forum entry "about redirect"
http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=858713
and find two solutions :
1. script : based on forum entry:
DEBUG=""
if [ "${DEBUG}" = "Y" ]
then
OUTPUTDEVNULL="" # i should see the output
else
OUTPUTDEVNULL="/dev/null"
fi
echo "test" > ${OUTPUTDEVNULL} 2>&
2. script : example with exec
DEBUG=""
if [ "${DEBUG}" = "Y" ]
then
exec 3>&2 # i should see the output
else
exec 3>/dev/null
fi
echo "test" >&3
exec 3>&- # close the file descriptor
what i the best solution ? other way to solve this ?
regards
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-02-2009 04:15 AM
тАО04-02-2009 04:15 AM
Solution
Hi:
I use something like this:
# cat ./debug.sh
#!/usr/bin/sh
DEBUG=0 && [ "${1}" = "-d" ] && DEBUG=1
echo "...this is output..."
[ ${DEBUG} = 0 ] && exec > /dev/null 2>&1
echo "...this you don't see if debugging off..."
...run:
# ./debug.sh
...and compare to:
# ./debug.sh -d
Regards!
...JRF...
I use something like this:
# cat ./debug.sh
#!/usr/bin/sh
DEBUG=0 && [ "${1}" = "-d" ] && DEBUG=1
echo "...this is output..."
[ ${DEBUG} = 0 ] && exec > /dev/null 2>&1
echo "...this you don't see if debugging off..."
...run:
# ./debug.sh
...and compare to:
# ./debug.sh -d
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-02-2009 06:23 AM
тАО04-02-2009 06:23 AM
Re: control (enable/disable) redirect to /dev/null
thx for the fast answer.
can i redirect to stdout maybe for a message which should always appear ?
[ ${DEBUG} = 0 ] && exec > /dev/null 2>&1
echo "...this you don't see if debugging off..."
echo "other output ..."
the command for redirect to stdout ?
exec >& -
echo "output allways appears"
regards
can i redirect to stdout maybe for a message which should always appear ?
[ ${DEBUG} = 0 ] && exec > /dev/null 2>&1
echo "...this you don't see if debugging off..."
echo "other output ..."
the command for redirect to stdout ?
exec >& -
echo "output allways appears"
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-02-2009 06:28 AM
тАО04-02-2009 06:28 AM
Re: control (enable/disable) redirect to /dev/null
Hi (again):
Why not use STDERR for what is is intended (?):
# cat ./debug.sh
#!/usr/bin/sh
DEBUG=0 && [ "${1}" = "-d" ] && DEBUG=1
echo "...this is output..."
[ ${DEBUG} = 0 ] && exec > /dev/null
echo "...this you don't see if debugging off..."
print -u2 "...STDERR reporting here..."
Regards!
...JRF...
Why not use STDERR for what is is intended (?):
# cat ./debug.sh
#!/usr/bin/sh
DEBUG=0 && [ "${1}" = "-d" ] && DEBUG=1
echo "...this is output..."
[ ${DEBUG} = 0 ] && exec > /dev/null
echo "...this you don't see if debugging off..."
print -u2 "...STDERR reporting here..."
Regards!
...JRF...
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.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP