Skip to content

Question: fish command which starts with a subshell #936

Closed

Description

@d5ve

In bash, I've been using a command like the following to check queue lengths on gearman daemons. The subshell and sleep are to (as far as I can tell) keep the connection to the gearmand open long enough to get a response over a slow link.

# Sometimes returns no data over a slow link
$ echo status | netcat gearmand-01 7003
# Keeps connection open long enough to get reply.
$ (echo status ; sleep 0.5) | netcat gearmand-01 7003

I've been unable to work out an equivalent command with fish, as it seems like you can't start a command with a subshell. Is there another way of doing this?

There is a slow workaround doing something like the following, but it has only second-resolution, so the command will take at least 2 seconds to complete, which adds up when many hosts are being polled.

# Use the interval param to netcat
$ echo status | netcat -i 1 gearmand-01 7003

Cheers,

Dave

Activity

  1. ridiculousfish commented on Jul 29, 2013

    @ridiculousfish
    Member

    Try this:

    begin ; echo status ; sleep 0.5 ; end | netcat gearmand-01 7003 
    
  2. d5ve commented on Jul 29, 2013

    @d5ve
    Author

    Thanks for the comment. I tried the following command as suggested, but didn't get back any response.

    begin ; echo status ; sleep 0.5 ; end | netcat gearmand-01 7003 
    

    It appears that there is a difference in behaviour between both methods.

  3. sugar700 commented on Jul 29, 2013

    @sugar700
    Contributor

    Yeah, it seems that fish waits 0.5 seconds before outputing status (for some reason, pipes with blocks are broken in fish shell).

  4. nicktimko commented on Nov 9, 2016

    @nicktimko

    Or a simpler question: how to replicate something like $(brew --prefix mysql)/bin/mysqladmin. Using (brew --prefix mysql)/bin/mysqladmin chokes because it's an "Illegal command name"

  5. krader1961 commented on Nov 9, 2016

    @krader1961
    Contributor

    The solution today is eval (brew --prefix mysql)/bin/mysqladmin). The long term solution to this limitation will be addressed in issue #154.

  6. krader1961 commented on Mar 15, 2017

    @krader1961
    Contributor

    The alternative to (...) is fish -c; e.g., fish -c 'echo status; sleep 0.5'.

  7. foxpy commented on Mar 1, 2019

    @foxpy

    Try this:

    begin ; echo status ; sleep 0.5 ; end | netcat gearmand-01 7003 
    

    But how do I do this?

    time begin
        # code
    end
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions