# set variable PATH

**URL:** <https://forums.suse.com/t/set-variable-path/33052>\
**Category:** SLES Configure-Administer\
**Created:** [October 16, 2018, 3:12pm UTC](https://forums.suse.com/t/set-variable-path/33052 "2018-10-16T15:12:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![phrix](https://avatars.discourse-cdn.com/v4/letter/p/d2c977/32.png) [@phrix](https://forums.suse.com/u/phrix)\
**Post date:** [October 16, 2018, 3:12pm UTC](https://forums.suse.com/t/set-variable-path/33052/1 "2018-10-16T15:12:33Z")

</div>

Hello,

I am try set variable Path through script but donÂ´t work, my script:

#!/bin/bash

export PATH=$PATH:/usr/local/java/jdk1.7.0\_45:/usr/local/java/jdk1.7.0\_45/bin:/usr/dlc116:/usr/dlc116/bin

But after execute this script:

OE-DB:/etc/profile.d # printenv PATH  
/sbin:/usr/sbin:/usr/local/sbin:/root/bin:/usr/local/bin:/usr/bin:/bin

What I did wrong? and what is the best place to execute this script?

Thanks advanced.

---

<div class="post-metadata">

**Author:** ![malcolmlewis](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/malcolmlewis/32/11375_2.png) [@malcolmlewis](https://forums.suse.com/u/malcolmlewis)\
**Post date:** [October 16, 2018, 3:37pm UTC](https://forums.suse.com/t/set-variable-path/33052/2 "2018-10-16T15:37:02Z")

</div>

> [@](#):
>
> On Tue 16 Oct 2018 12:14:02 PM CDT, phrix wrote:
> 
> Hello,
> 
> I am try set variable Path through script but donÂ´t work, my script:
> 
> #!/bin/bash
> 
> export  
> PATH=$PATH:/usr/local/java/jdk1.7.0\_45:/usr/local/java/jdk1.7.0\_45/bin:/usr/dlc116:/usr/dlc116/bin
> 
> But after execute this script:
> 
> OE-DB:/etc/profile.d # printenv PATH  
> /sbin:/usr/sbin:/usr/local/sbin:/root/bin:/usr/local/bin:/usr/bin:/bin
> 
> What I did wrong? and what is the best place to execute this script?
> 
> Thanks advanced.

Hi  
In your ~/.profile or respective file in /etc/profile.d.

You can also set in a systemd service file as well (re your other  
thread)… In the [Service] section add;

```auto
Environment="PATH=...."
```

–  
Cheers Malcolm Â°Â¿Â° SUSE Knowledge Partner (Linux Counter #276890)  
SLES 15 | GNOME Shell 3.26.2 | 4.12.14-25.19-default  
If you find this post helpful and are logged into the web interface,  
please show your appreciation and click on the star below… Thanks!

---

<div class="post-metadata">

**Author:** ![phrix](https://avatars.discourse-cdn.com/v4/letter/p/d2c977/32.png) [@phrix](https://forums.suse.com/u/phrix)\
**Post date:** [October 16, 2018, 4:58pm UTC](https://forums.suse.com/t/set-variable-path/33052/3 "2018-10-16T16:58:48Z")

</div>

Yes I try run through the systemd service but didn’t work, when I type printenv PATH or echo $PATH, the directories added don’t are in the variable.

See:

Using keyboard-interactive authentication.  
Password:  
Last login: Tue Oct 16 08:39:48 2018 from 192.168.0.113  
OE-DB:~ # systemctl status ini-server.service  
â ini-server.service - Roda comandos na inicializaÃ§ao -Pierre - 16/10/2018  
Loaded: loaded (/etc/systemd/system/ini-server.service; enabled; vendor preset: disabled)  
Active: inactive (dead) since Tue 2018-10-16 10:54:18 -03; 52s ago  
Process: 1022 ExecStart=/bin/sh -c /usr/local/bin/ini-server.sh (code=exited, status=0/SUCCESS)  
Main PID: 1022 (code=exited, status=0/SUCCESS)

Oct 16 10:54:14 OE-DB systemd[1]: Starting Roda comandos na inicializaÃ§ao -Pierre - 16/10/2018…  
Oct 16 10:54:14 OE-DB sh[1022]: OpenEdge Release 11.6.4 as of Tue Oct 3 01:15:46 EDT 2017  
Oct 16 10:54:18 OE-DB systemd[1]: Started Roda comandos na inicializaÃ§ao -Pierre - 16/10/2018.  
OE-DB:~ # printenv PATH  
/sbin:/usr/sbin:/usr/local/sbin:/root/bin:/usr/local/bin:/usr/bin:/bin

My script:

#!/bin/bash

export DLC=/usr/dlc116

export PATH=$PATH:/usr/local/java/jdk1.7.0\_45:/usr/local/java/jdk1.7.0\_45/bin:/usr/dlc116:/usr/dlc116/bin

proadsv -start

#eof

Is something wrong?

---

<div class="post-metadata">

**Author:** ![Jens-U](https://avatars.discourse-cdn.com/v4/letter/j/d78d45/32.png) [@Jens-U](https://forums.suse.com/u/Jens-U)\
**Post date:** [October 16, 2018, 7:45pm UTC](https://forums.suse.com/t/set-variable-path/33052/4 "2018-10-16T19:45:13Z")

</div>

Hi phrix,

> Is something wrong?

I do assume a conceptual misunderstanding: Environment variables are only set inside the current shell (or program) and then, if export’ed, available to any “sub-program” started from this shell/program.

So concerning your initial message:

[CODE]#!/bin/bash

export PATH=$PATH:/usr/local/java/jdk1.7.0\_45:/usr/local/java/jdk1.7.0\_45/bin:/usr/dlc116:/usr/dlc116/bin[/CODE]

will get executed in a shell of its own (because of the “shebang” #!/bin/bash) - there, the value is acutally set and exported, but then the shell is terminated. So after you have run that program and checked the value of PATH, you’ll see the value as it was set in the current, invoking shell - and there it never got changed.

So concerning your previous post, where you describe how you started the “proadsv” program and right before that exported the variables DLC and PATH, the proadsv program should actually have seen these variables with their new values. If the program remains active as a process, you can verify this by looking up the PID of the process and then check the content of /proc//environ for these variables.

Checking the variables from shells outside the setting program/shell and its subs will not work.

Regards,  
J

---

<div class="post-metadata">

**Author:** ![ab1](https://avatars.discourse-cdn.com/v4/letter/a/d2c977/32.png) [@ab1](https://forums.suse.com/u/ab1)\
**Post date:** [October 16, 2018, 9:22pm UTC](https://forums.suse.com/t/set-variable-path/33052/5 "2018-10-16T21:22:14Z")

</div>

On 10/16/2018 10:54 AM, jmozdzen wrote:[color=blue]

> Checking the variables from shells outside the setting program/shell and  
> its subs will not work.[/color]

Right, and if for some reason you want to have a script that you can call  
set environment variables in your CURRENT shell, then you can do so using  
the ‘source’ command, which essentially runs the commands int he called  
script in the current shell, rather than doing what you may be missing by  
default in that a call to a script calls a new sub-shell which, at the end  
of the script, exits, taking all of its updated environment variables with it.

```auto
source /pat/to/your/environment-setting-script.sh
```

–  
Good luck.

If you find this post helpful and are logged into the web interface,  
show your appreciation and click on the star below.

If you want to send me a private message, please let me know in the  
forum as I do not use the web interface often.

---

<div class="post-metadata">

**Author:** ![phrix](https://avatars.discourse-cdn.com/v4/letter/p/d2c977/32.png) [@phrix](https://forums.suse.com/u/phrix)\
**Post date:** [October 17, 2018, 2:20pm UTC](https://forums.suse.com/t/set-variable-path/33052/6 "2018-10-17T14:20:45Z")

</div>

Thanks for everyone’s help, really I was making a mess!  
I solved the problem by creating the /etc/profile.local file that was just what I needed, but since the file did not exist I did not know it was just to create.
