bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Environment variable "PS4" can not be passed to bash script from ver


From: Greg Wooledge
Subject: Re: Environment variable "PS4" can not be passed to bash script from version 4.2.46(2)
Date: Tue, 23 Oct 2018 12:06:06 -0400
User-agent: NeoMutt/20170113 (1.7.2)

On Tue, Oct 23, 2018 at 03:20:12PM +0000, Chen, Farrah wrote:
> But in Bash script, it cannot work, it keeps its original value:
> [root@fchen ~]# cat test.sh
> #!/usr/bin/bash
> echo $PS4
> echo $FAN

This is because you're doing it as root.  Bash strips PS4 from the
environment when started as root, as a security precaution.

wooledg:~$ PS4='hello' bash -c 'set -x; true'
hellotrue
wooledg:~$ sudo env PS4='hello' bash -c 'set -x; true'
[sudo] password for wooledg: 
+ true

Notice how it works as expected as a regular user, then "fails"
under sudo.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]