args: Enables a program to get arguments when piped

args in a nut-shell:

#! /bin/bash
echo $(args "${@}")
$ echo "${USER}" | program "My name is"
My name is bond

1 Like

What's the difference to xargs?

echo "$USER" | xargs echo "My name is"
1 Like

args goal is to distinguish automatically if the command is piped or not:

$ args echo "This"
This

$ xargs echo "This"
(hangs)

It's not hanging, it's waiting for user input:

$ xargs echo "This"
works
[Press Ctrl+D]
This works

This is the standard behaviour of almost all commands expecting input. If you really also need to run the command from a terminal without piping input into it, a possible solution would be

( [ -t 0 ] || cat ) | xargs echo "This"

This uses cat to relay the input to xargs if run from a pipe. When run from a terminal, [ -t 0 ] evaluates to true, passing an empty input to xargs so that echo "This" is executed.

1 Like

The idea is to nest any know-how inside commands, instead of documentation.

To turn Bash into an expressive language.

Master Foo and the Shell Tools

1 Like

Forum kindly sponsored by