A missing command line tool for the Unix desktop

Sun 23 June 2013 by Stig Inge Lea Bjørnsen

On my Linux desktop, I find it useful to paste information onto the command line and then process it using Unix command line tools.

For this I use a small script that simply writes its arguments to standard out, each argument on a separate line.

The script is called argo, an abbreviation of "arguments out".

Here is what it does:

$ argo arg1 arg2 arg3
arg1
arg2
arg3
$

Here is how I often use it:

$ argo <pasted md5sum> $(md5sum foo.bin) | uniq
<pasted md5sum>
foo.bin
$

This is the script:

#!/bin/bash

if [[ "$#" == "0" || "$1" == "-h" ]] ; then
    echo "Usage:"
    echo "$(basename $0) arg1 arg2 .. argN     Print the arguments to stdout separated by newlines."
    echo "$(basename $0) -- arg1 arg2 .. argN  Treat everything after -- as literal arguments."
    echo "$(basename $0) -h                    Display help"
    exit 0
fi

if [[ "$1" == "--" ]] ; then
    shift
fi

while (( "$#" )) ; do
    echo $1
    shift
done

exit 0

As more and more users are adopting a Unix variant as their desktop OS, I figure someone else out there will find it useful to invoke a command pipeline that starts with user input.

PS! Did you notice that the argo script is the inverse of command substitution in Bash:

$ echo $(argo arg1 arg2 arg3)
arg1 arg2 arg3
$

Share on: Hacker NewsProggitTwitter