Consider a script pass_command

ls | "$@"

It accepts named commands as arguments

pass_command sort
#prints files sorted

Which is good enough for all practical purposes. I'm curious though, Is there a mechanism that lets me pass compound commands? Something like

pass_command (sort | uniq) #Forgive the silly example.

Edit: A more complicated example that motivated this question.

until who | grep mary
  sleep 60

Signals mary logging on. I wanted to generalize this to signal some event. The intuitive idea was this:

until "$@"
  sleep 60

And then you would call it as

watchfor (who | grep mary)

That was the idea. You can give the argument a name, and the above works fine. It just made me think of this.

I suppose I was trying to understand the most idiomatic way of hiding the signaling command.

1 Answer 1


You would have to use eval in the script as soon as $@ is more than a simple command (the argument to the script has to be passed as a quoted string):

ls | eval "$@"

But then again, this would also be the same as

pass_command sort | uniq

i.e., you pass the sort command and the use uniq on the output.

I see no real use for this sort of script or function as Unix's pipelining capability seems to cover most practical applications.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .