- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Environment Variables
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-26-2007 06:10 PM
10-26-2007 06:10 PM
whats the difference between ` & ' in variables & how do i set my shell prompt to show hostname and present working directory.
Thanks in advance
Dinesh
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2007 06:33 PM
10-26-2007 06:33 PM
Re: Environment Variables
insert this line in your .profile
PS1=`hostname`:'$PWD'#
export PS1
show hostname and present working directory
Fat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2007 06:56 PM
10-26-2007 06:56 PM
Re: Environment Variables
For more information about shell and vars. anv see this guide:
http://www.phys.ualberta.ca/~gingrich/research/shells/shells.html
Fat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2007 07:54 PM
10-26-2007 07:54 PM
Re: Environment Variables
Thanks for your reply. I want to know when commands inserted between the ` characters its being executed and we are getting the output. As well as why the same character is not being used to get the output of PWD in this location.
Rgds,
Din
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2007 08:52 PM
10-26-2007 08:52 PM
Solutionin a shell script you can capture the output of the command in these ways:
VAR=`hostname`
or
VAR=$(hostname)
In a command script you use a command between `hostname` the shell try to exec not the command but its output
From command line try to exec `hostname` and see what error appears.
For create a PS1 var, in your case, must be execute a command to show the hostname, and an env var to show the current directory.
PS1=`hostname`:'$PWD'#
Fat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2007 09:06 PM
10-26-2007 09:06 PM
Re: Environment Variables
nowadays you will often see the newer standard:
$(command)
instead of
`command`
However, the result is the same; commands in between are always executed/processed, e.g.
$ echo $(date +%a)
or
$ echo `date +%a`
in the example the date command is executed first and the echo command then displays the result.
In contrast, you can display the current value of a variable by just echoing it, e.g.:
echo "$PWD"
notice the use of double quotes, as one significant difference between single and double quotes is that any character in between single quotes is taken literally, e.g.:
echo '$PWD'
and a bit simplified you can say that the difference between single/double quotes and back quotes/$() is that using single/double quotes does not impose any processing on the string in between; you simply display the current content.
But the back quoutes/$() causes command execution of whatever in between.
However, PWD is a special variable because the shell supplies the content of it; the content is updated every time you change directory, e.g.:
$ echo $PWD
/home/john
you can change the content
$ PWD="hoooops"
$ echo $PWD
hoooops
but the shell will overrule it when you change directory
$ cd
echo $PWD
/home/john
So what may be confusing in contrast to a "non reserved, home made" variable is that the content of PWD is automatically updated by the shell.
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2007 09:21 PM
10-26-2007 09:21 PM
Re: Environment Variables
I was having bit confusion on this subject. Now its got cleared.
Thanks
Dinesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2007 09:21 PM
10-26-2007 09:21 PM