Berkeley CSUA MOTD:Entry 28085
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/05/24 [General] UID:1000 Activity:popular
5/24    

2003/4/11-12 [Computer/SW/Languages, Computer/SW/Unix] UID:28085 Activity:nil
4/11    Why is anything being printed?
        bash-2.05b$ mkdir tmp 2>&1 > /dev/null
        mkdir: tmp: File exists
               \- use this "mkdir tmp  > /dev/null 2>&1" --psb
                  \_ thanks. (mkdir tmp 2>&1) > /dev/null wasnt as purty.
        \_ The order of evaluation is important:
           2>&1         -> dup2(1,2)
           --> 2 is now a copy of 1
           1> /dev/null -> fd = open("/dev/null",O_RDONLY);
                           dup2(fd,1);
           --> 1 is a copy of fd, 2 remains a copy of what 1 was.