Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I've noticed an odd behavior on my Ubuntu 12.04 LTS system. This is my first experience with Ubuntu; previously I used Fedora and never had this problem.

I have set my umask in .bashrc to 0027. But it automatically changes to 0002 every time I cd into another directory. It doesn't matter what directory I go in to; every directory change results in the umask changing.

bbrown@cs:~$ umask
0027
bbrown@cs:~$ cd /
bbrown@cs:/$ umask
0002
bbrown@cs:/$ umask 027
bbrown@cs:/$ cd /var/log
bbrown@cs:/var/log$ umask
0002

It even happens if I just use cd without a directory:

bbrown@cs:/var/log$ cd
bbrown@cs:~$ umask 027
bbrown@cs:~$ umask
0027
bbrown@cs:~$ cd
bbrown@cs:~$ umask
0002

I've searched through some other discussion boards. A similar question was asked on Stack Overflow with no resolution.

I have no special ACLs on any of these directories.

bbrown@cs:/var/log$ getfacl /
getfacl: Removing leading '/' from absolute path names
# file: .
# owner: root
# group: root
user::rwx
group::r-x
other::r-x

bbrown@cs:/var/log$ getfacl /var/log
getfacl: Removing leading '/' from absolute path names
# file: usr/bin
# owner: root
# group: root
user::rwx
group::r-x
other::r-x

Filesystems are ext4 with no ACL mounting options:

bbrown@cs:/var/log$ more /etc/fstab
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    nodev,noexec,nosuid 0       0
/dev/mapper/vg0-root /               ext4    errors=remount-ro 0       1
# /boot was on /dev/vda1 during installation
UUID=0da490ac-183d-45cd-a490-5d7ac3663337 /boot           ext2    defaults        0       2
/dev/mapper/vg0-export /export         ext4    defaults        0       2
/dev/mapper/vg0-home /home           ext4    defaults        0       2
/dev/mapper/vg0-var /var            ext4    defaults        0       2
/dev/mapper/vg0-mysql /var/lib/mysql  ext4    defaults        0       2
/dev/mapper/vg0-pgsql /var/lib/postgresql ext4    defaults        0       2
/dev/mapper/vg0-swap none            swap    sw              0       0

The csh does not exhibit this behavior; it's bash only as far as I can tell.

What's going on and how do I disable this?

Update

I copied bash from my Fedora 13 system and put it in my home directory. That version does not exhibit the problem.

bbrown@cs:~$ /bin/bash --version
GNU bash, version 4.2.24(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
bbrown@cs:~$ ls -l /bin/bash
-rwxr-xr-x 1 root root 955024 Apr  3 08:58 /bin/bash
bbrown@cs:~$ ls -l ./bash
-rwxr-xr-x 1 bbrown bbrown 904664 Sep 11 13:02 ./bash
bbrown@cs:~$ ./bash --version
GNU bash, version 4.1.7(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
bbrown@cs:~$ exec ./bash
bbrown@cs:~$ umask
0027
bbrown@cs:~$ cd /
bbrown@cs:/$ umask
0027

As requested, here's the output of type cd:

bbrown@cs:~$ type cd
cd is a function
cd () 
{ 
    if builtin cd "$@"; then
        [[ -n "${rvm_current_rvmrc:-}" && "$*" == "." ]] && rvm_current_rvmrc="" || true;
        __rvm_do_with_env_before;
        __rvm_project_rvmrc;
        __rvm_after_cd;
        __rvm_do_with_env_after;
        return 0;
    else
        return $?;
    fi
}

That's telling. RVM has taken control of the cd command. That's annoying, but it certainly explains what's going on.

share|improve this question
    
Just to get the obvious out of the way: type cd? –  jw013 Sep 11 '12 at 20:05
    
Do you have a .bash_profile or a .bash_login file present? .profile won't be read in this case. –  ire_and_curses Sep 11 '12 at 20:05
    
@jw013: Updated with cd only. –  Barry Brown Sep 11 '12 at 20:10
    
@ire_and_curses You're right; I actually use a .bashrc –  Barry Brown Sep 11 '12 at 20:12
1  
@BarryBrown I meant to post the output of type cd. –  jw013 Sep 11 '12 at 20:18
show 1 more comment

1 Answer

cd doesn't change the umask. Either you've overloaded cd, or you have a pre- or post-command hook.

Check that cd hasn't been overloaded by running type cd. This will show you whether it's a “shell builtin” (good) or an alias or function (suspicious).

Run echo "$PROMPT_COMMAND" to see if you have a post-command hook (bash evaluates the value of this variable before displaying each prompt). Also check for a debug trap which is executed before each command with trap -p DEBUG.

share|improve this answer
    
Yup, that's it exactly. I didn't realize that RVM had overridden cd. Now I need to figure out how to restore things to the way they should be. –  Barry Brown Sep 12 '12 at 3:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.