- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- simple script
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
тАО11-29-2001 07:23 AM
тАО11-29-2001 07:23 AM
This is driving me crazy (short trip). Here's a simple script:
if [ "$DISPLAY" ]
then
echo DISPLAY $DISPLAY
else
term=`tty | cut -c6-`
export DISPLAY=`who -u | grep "$term " | awk '{print $1}'`":0.0"
fi
It seems the script runs fine in a subshell (./script) but I know I have to run it in my current shell (. ./script) to get the desired result. Here's the problem:
When I run ". ./script" it fails with:
sh: DISPLAY: Parameter not set.
It doesn't matter if my shell is specified in /etc/passwd as /sbin/sh, /usr/bin/sh, or /usr/bin/ksh. I get the error regardless.
Another oddity is that if I simply go into another shell after logging in, the script then works as desired. Again, it doesn't matter which of the 3 shells I choose.
Thanks for helping,
Darrell
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-29-2001 07:34 AM
тАО11-29-2001 07:34 AM
SolutionYour .profile is sourced into your login (ie interactive) shell environment (ie not run as a shell script) which has the -u flag set to error on unknown variables. To see:
$ print $wibble
sh: wibble: Parameter not set.
$ set +u
$ print $wibble
$
So to get round it either:
1) Set a variable before you use it. (Remember that even in quotes if a variable doesn't exist the shell *still* looks at it)
2) Use set +u like above, don't forget to unset it afterwards.
3) Use the shell construct:
variable=${variable:-NOTSET}
(which states if variable is unset set it to NOTSET otherwise set it to the contents of variable)
I'd advise using 3, this is a very good safety measure to use in any shell script!
One other thing to remember is the difference between a non-existant variable and a blank one. eg:
$ echo $fred
sh: fred: Parameter not set.
$ fred=
$ echo $fred
$
dave
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-29-2001 08:03 AM
тАО11-29-2001 08:03 AM
Re: simple script
I added "set +u" at the beginning of my script.
Why would I want to use "set -u" anyway?
Thanks,
Darrell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-29-2001 08:45 AM
тАО11-29-2001 08:45 AM
Re: simple script
rm -rf /${ADIR}
mv /${ADIR} /tmp/backup
imagine if you executed on of the above without ADIR set or accidently mistyped it as SDIR and pressed return without noticing?
dave
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-29-2001 09:09 AM
тАО11-29-2001 09:09 AM
Re: simple script
Guess I wasn't thinking (what else is new).
Thanks,
Darrell