News for hackers. Stuff that matters.
Re:Adventures in /usr/bin and the likes by akerl_ on Monday February 20, 2017 @12:19AM (#13684492)
I'm never 100% sure I understand FD redirection, but I think you can shorten that even further to:

    function cip() {
        resolveip -s $1 1>&2 | xsel -b
    }
Since this'll copy stdout to stderr, and then stdout will get eaten by xsel
Re:Adventures in /usr/bin and the likes by xelxebar on Monday February 20, 2017 @02:36AM (#13685223)
A little spelunking may help:

    $ lsof  -d 0,1,2 -a -p $$
That will show you what files correspond to what file descriptors for your current shell process. You can then experiment with redirects. To see how a pipe works we can do something similar:

    $ sleep 1 | lsof -d 0,1,2 -a -p $(sh -c 'echo $PPID')
Anyway, thinking of `>` and `<` as just FD setters made things a lot clearer for me personally. They just set the file descriptor on the left to file on the right and `&n` can be used to "dereference" a FD to its corresponding file. The only real difference between `>` and `<` is that the former opens the file with write permission while the latter opens it with read. Well, and the default FDs are different.

Incidentally, this makes it clear why the following doesn't work as expected:

    $ curl 'https://kernel.org/' >/dev/null 2>&1 | tee curl.errs
Since FDs get set in the order they are specified, 1 gets set to /dev/null and then 2 gets set to whatever 1 is, i.e /dev/null. So it's clear that we probably intended the following:

    $ curl 'https://kernel.org/' 2>&1 >/dev/null | tee curl.errs
Which lets us ignore stdin and maybe pipe stdout to some other command.

Now I hope Linus doesn't hate on me for abusing kernel.org :P

Re:Adventures in /usr/bin and the likes by tomsmeding on Monday February 20, 2017 @02:15AM (#13685107)
It won't copy stdout to stderr; it'll move stdout to stderr. Stdout will be empty after the redirect, so no, thos won't work :)
Re:Adventures in /usr/bin and the likes by akerl_ on Monday February 20, 2017 @07:02AM (#13686568)
Have you tried it out? It worked on my system.
Re:Adventures in /usr/bin and the likes by IsmaOlvey on Monday February 20, 2017 @07:54AM (#13686807)
The parent is correct, the given command redirects stdout to stderr, it's not copied (so stdout will be empty).
Re:Adventures in /usr/bin and the likes by akerl_ on Monday February 20, 2017 @09:04AM (#13687273)
Again, have you tried it?

    # echo "foo" 1>&2 | sed 's/foo/bar/'
    foo
    bar
Edit: I've done some more testing, and discovered that the above works on zsh, but not in bash

2nd Edit: Ahha! http://www.cs.elte.hu/zsh-manual/zsh_7.html . So this is because zsh w/ the stock config (MULTIOS option enabled) will open as many outputs as you give it. So it can both copy FD 1's contents to FD 2 and to the pipe'd command.