Path: csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail From: Greg Wooledge Newsgroups: gnu.bash.bug 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 Lines: 19 Approved: bug-bash@gnu.org Message-ID: References: <1B925CC0CD9F3341B32D442251E7E1DC392DBFC8@shsmsx102.ccr.corp.intel.com> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: usenet.stanford.edu 1540310808 20713 208.118.235.17 (23 Oct 2018 16:06:48 GMT) X-Complaints-To: action@cs.stanford.edu Cc: "bug-bash@gnu.org" To: "Chen, Farrah" Envelope-to: bug-bash@gnu.org Mail-Followup-To: "Chen, Farrah" , "bug-bash@gnu.org" Content-Disposition: inline In-Reply-To: <1B925CC0CD9F3341B32D442251E7E1DC392DBFC8@shsmsx102.ccr.corp.intel.com> User-Agent: NeoMutt/20170113 (1.7.2) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 139.137.100.1 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.bash.bug:14733 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.