Results 1 to 2 of 2

Thread: Avoiding clashes in --listen, like exec 4> >(fn)

  1. #1
    Join Date
    Mar 2007
    Location
    Manchester, UK
    Beans
    101
    Distro
    Ubuntu 9.10 Karmic Koala

    Question Avoiding clashes in --listen, like exec 4> >(fn)

    If I run a simple bash script notification, for example

    Code:
    exec 4> >(zenity --notification --listen)
    how can I be sure there won't be a clash between two scripts on the same channel?

    Obviously, I could number each script uniquely but then I've got to keep a tab on that number.

    So exec 3> or exec 4> etc.

    Is there an option to assign the number of the next available channel to a local variable for that script?

  2. #2
    Join Date
    Feb 2007
    Beans
    4,045
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Avoiding clashes in --listen, like exec 4> >(fn)

    There's no clash; every process have their own set of fds, they are inherited by child processes however.

    E.g.
    Code:
    $ exec 4> >(rev)
    $ bash -c 'echo foo >&4'
    oof
    $ exec 4>&-
    Code:
    $ bash -c 'exec 4> >(rev); read' &
    [1] 16306
    $ echo foo >&4
    bash: 4: Bad file descriptor
    In the latter, fd 4 is opened by a child process, and you can see it does not affect the parent.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •