LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   'source' behaves differently in RHEL 5 and 6 (https://www.linuxquestions.org/questions/linux-newbie-8/source-behaves-differently-in-rhel-5-and-6-a-4175509610/)

Jerry Mcguire 06-30-2014 12:22 AM

'source' behaves differently in RHEL 5 and 6
 
In RHEL5.4, the following entries in the crontab works:

* * * * * set >/tmp/set.output
* * * * * . my_env && cat my_env >/tmp/deleteme

The file my_env is placed under my home directory with mode 644 owned by me. The file /tmp/set.output and /tmp/deleteme are created as expected.

However the same entries and the same setup doesn't work in RHEL6.4. It doesn't create or write to /tmp/deleteme although I have permission to create files and write to them in /tmp.

The man page says `source` will look for my_env from the PATH. On non-posix shell, the home directory is searched as well. So RHEL6.4 is correct. I wonder if this is an intended improvement or is it something else that makes the behaviour different?

RHEL5.4:
Code:

$ cat /tmp/set.output
BASH=/bin/sh
BASH_ARGC=()
BASH_ARGV=()
BASH_EXECUTION_STRING='set >/tmp/set.output'
BASH_LINENO=()
BASH_SOURCE=()
BASH_VERSINFO=([0]="3" [1]="2" [2]="25" [3]="1" [4]="release" [5]="x86_64-redhat-linux-gnu")
BASH_VERSION='3.2.25(1)-release'
DIRSTACK=()
EUID=5111
GROUPS=()
HOME=/var/hello
HOSTNAME=hello
HOSTTYPE=x86_64
IFS='       
'
LOGNAME=hello
MACHTYPE=x86_64-redhat-linux-gnu
OPTERR=1
OPTIND=1
OSTYPE=linux-gnu
PATH=/usr/bin:/bin
POSIXLY_CORRECT=y
PPID=27700
PS4='+ '
PWD=/var/hello
SHELL=/bin/sh
SHELLOPTS=braceexpand:hashall:interactive-comments:posix
SHLVL=1
TERM=dumb
UID=5111
USER=hello
_=/bin/sh

RHEL6.3:
Code:

$ cat /tmp/set.output
BASH=/bin/sh
BASHOPTS=cmdhist:extquote:force_fignore:hostcomplete:interactive_comments:progcomp:promptvars:sourcepath
BASH_ALIASES=()
BASH_ARGC=()
BASH_ARGV=()
BASH_CMDS=()
BASH_EXECUTION_STRING='set >/tmp/set.output'
BASH_LINENO=()
BASH_SOURCE=()
BASH_VERSINFO=([0]="4" [1]="1" [2]="2" [3]="1" [4]="release" [5]="x86_64-redhat-linux-gnu")
BASH_VERSION='4.1.2(1)-release'
DIRSTACK=()
EUID=5104
GROUPS=()
HOME=/home/hello
HOSTNAME=hello
HOSTTYPE=x86_64
IFS='       
'
LOGNAME=hello
MACHTYPE=x86_64-redhat-linux-gnu
OPTERR=1
OPTIND=1
OSTYPE=linux-gnu
PATH=/usr/bin:/bin
POSIXLY_CORRECT=y
PPID=23161
PS4='+ '
PWD=/home/hello
SHELL=/bin/sh
SHELLOPTS=braceexpand:hashall:interactive-comments:posix
SHLVL=1
TERM=dumb
UID=5104
USER=hello
_=/bin/sh

I have changed some output to 'hello' for privacy.

Jerry Mcguire 06-30-2014 12:42 AM

More info:
As you can see, the home directories are at different locations on RHEL 5 and 6. So they are not exactly the same.

The home directory on RHEL 5 is /var/hello with mode 755.
The home directory on RHEL 6 is /home/hello with mode 700.

Yet I don't think they make a different in my case, do they?

Jerry Mcguire 06-30-2014 01:47 AM

A friend sent me a official explanation with the following link.

https://access.redhat.com/site/docum...nges-Bash.html

"Bash-4.0 and later fixes a Posix mode bug that caused the . (source) builtin to search the current directory for its filename argument, even if "." is not in the system PATH. Posix says that the shell should not look in the PWD variable in this case."

It is indeed a bug-fix in bash.


All times are GMT -5. The time now is 04:00 PM.