×
UNIX.COM Login
Username:
Password:  
Show Password






👤


HP-UX

HP-UX (Hewlett Packard UniX) is Hewlett-Packard's proprietary implementation of the Unix operating system, based on System V.

Set, setenv or export? Confused between three options

👤 Login to reply

 
Thread Tools Search this Thread Display Modes
    #1  
Old 04-24-2017
userexperience userexperience is offline
Registered User
 
Join Date: Apr 2017
Last Activity: 24 April 2017, 5:28 AM EDT
Location: singapore
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Set, setenv or export? Confused between three options

Hi Experts,

Need your help in understanding the commands to setup the environment variables in hp-ux.

Beleive need to use either set,setenv or export.

I am confused between above three options, when to use which option?

On command line, I have tried both set and setenv but couldn't able to set the environment variables. However with export it was working fine.
Sponsored Links
    #2  
Old 04-24-2017
MadeInGermany MadeInGermany is offline Forum Staff  
Moderator
 
Join Date: May 2012
Last Activity: 16 July 2018, 7:08 AM EDT
Location: Simplicity
Posts: 4,153
Thanks: 365
Thanked 1,418 Times in 1,274 Posts
With standard shell or compatible shell (/etc/passwd has /bin/sh or /bin/ksh or /bin/bash or /bin/zsh) it uses


Code:
var=value

for a shell-internal variable. And


Code:
export var

to promote it to environment. Environment is inherited by the commands that the shell invokes.
The standard shell and compatibles process such commands in $HOME/.profileat a login.

If the shell in /etc/passwd is /bin/csh or /bin/tcsh then the syntax is different:


Code:
set var=value

for shell-internal, and


Code:
setenv var=value

for environment. There is some confusion if you do both with the same variable. By convention you should do


Code:
set var=value
setenv VAR=value

I.e. lowercase of internal variables and uppercase for environment variables.
The csh and tcsh process such commands in $HOME/.loginat a login.

Usually the SHELL environment variable is set from the one in /etc/passwd:


Code:
echo $SHELL


Last edited by vbe; 04-25-2017 at 03:08 AM.. Reason: typo
Sponsored Links
    #3  
Old 04-25-2017
vbe's Unix or Linux Image
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Last Activity: 16 July 2018, 6:16 AM EDT
Location: Switzerland - GE
Posts: 6,550
Thanks: 311
Thanked 564 Times in 526 Posts
You did not say what version of HP-UX you are working on...
Till 11.23 ( after I dont know...) the default user shell was ksh , so you would use either .profile or .kshrc in your home directory, for root user its a little different...
I will add to previous post that you can in .kshrc and even in .profile now ( since 11.00 ? ) use also this syntax:


Code:
export VAR=value

    #4  
Old 04-25-2017
MadeInGermany MadeInGermany is offline Forum Staff  
Moderator
 
Join Date: May 2012
Last Activity: 16 July 2018, 7:08 AM EDT
Location: Simplicity
Posts: 4,153
Thanks: 365
Thanked 1,418 Times in 1,274 Posts
A correction: ksh does not take .kshrc. It takes an environment variable ENV.
You can of course put the following into .profile


Code:
#ksh takes this startup file:
ENV=$HOME/.kshrc; export ENV

The Following User Says Thank You to MadeInGermany For This Useful Post:
vbe (04-25-2017)
Sponsored Links
    #5  
Old 04-25-2017
vbe's Unix or Linux Image
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Last Activity: 16 July 2018, 6:16 AM EDT
Location: Switzerland - GE
Posts: 6,550
Thanks: 311
Thanked 564 Times in 526 Posts
Thanks for the correcting me, was so obvious I zapped the magic line you need in .profile ...
There is a good reason to use a .kshrc if you use/have heavy customisation.:
To be sure no one has a corrupt environment when upgrading/patching OS if a new .profile is provided in the upgrade, it will be used as default for all users, thus avoiding extra most probable useless calls to internal support team... and as MadeInGermany flagged, the only thing we check here is that the magic line is present , if not will be added to the default...

Things get more complicated when using X server on PC with ssh and have an heterogenous environment with many flavours of UX/linux...
Sponsored Links
    #6  
Old 04-25-2017
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 16 July 2018, 1:02 AM EDT
Location: San Jose, CA, USA
Posts: 11,406
Thanks: 649
Thanked 3,969 Times in 3,393 Posts
Quote:
Originally Posted by MadeInGermany View Post
A correction: ksh does not take .kshrc. It takes an environment variable ENV.
You can of course put the following into .profile


Code:
#ksh takes this startup file:
ENV=$HOME/.kshrc; export ENV
If ENV is found in the environment when an interactive ksh is invoked, then parameter expansion, command substitution, and arithmetic substitution are performed on the value of $ENV to generate the pathname of a script that will be executed before the first prompt is issued. If ENV is not found in the environment when an interactive ksh is invoked and there is a file named .kshrc in your login directory, that file will be executed before the first prompt is issued.

Depending on how ksh is configured on your system, it may also look for /etc/ksh/.kshrc. On systems that are configured to use this file, you can skip executing it by setting ENV to a string starting with /./ or ././ (such as /.$HOME/.kshrc to execute only $HOME/.kshrc or /./dev/null to avoid executing either of those files).
Sponsored Links
    #7  
Old 04-25-2017
Neo's Unix or Linux Image
Neo Neo is online now Forum Staff  
Administrator
 
Join Date: Sep 2000
Last Activity: 16 July 2018, 8:48 AM EDT
Location: Asia pacific region
Posts: 14,535
Thanks: 1,025
Thanked 1,426 Times in 690 Posts
Hello,

Per our forum rules, all threads must have a descriptive subject text. For example, do not post questions with subjects like "Help Me!", "Urgent!!" or "Doubt". Post subjects like "Execution Problems with Cron" or "Help with Backup Shell Script".

The reason for this is that nearly 95% of all visitors to this site come here because they are referred by a search engine. In order for future searches on your post (with answers) to work well, the subject field must be something useful and related to the problem!

In addition, current forum users who are kind enough to answer questions should be able to understand the essence of your query at first glance.

So, as a benefit and courtesy to current and future knowledge seekers, please be careful with your subject text. You might receive a forum infraction if you don't pay attention to this.

Thank you.

The UNIX and Linux Forums
Sponsored Links
👤 Login to reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
setenv. max_475 UNIX for Advanced & Expert Users 7 12-17-2008 08:03 PM
difference between EXPORT and setenv dexkid UNIX for Dummies Questions & Answers 3 02-07-2008 02:06 AM
setenv in script kosta_mirkin Shell Programming and Scripting 2 01-12-2005 12:28 AM
What 's setenv? myoeminn Shell Programming and Scripting 2 03-05-2002 08:24 PM



All times are GMT -4. The time now is 08:48 AM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.