Environment variables are not working for non-interactive shells.
Issue
-
Defining environment variables in
~/.kshrc
for a user withksh
as the login shell works on an interactive shell:[root@server ~]# su - user Last login: Fri Dec 20 11:08:13 CET 2024 on pts/1 $ whoami user $ echo $SHELL /usr/bin/ksh $ tail -n2 ~/.kshrc # User specific aliases and functions export VAR=/opt $ echo $VAR /opt $
-
However the same fails when using
su - <USER> -c
instead:[root@server ~]# su - svchpsuat -c "echo $VAR" [root@server ~]#
-
The same behaviour applies to
bash
and~/.bashrc
Environment
- Red Hat Enterprise Linux 7
- Red Hat Enterprise Linux 8
- Red Hat Enterprise Linux 9
- ksh
- bash
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.