Skip to content

Instantly share code, notes, and snippets.

@maplebed
Last active December 30, 2015 01:19
Show Gist options
  • Save maplebed/7755772 to your computer and use it in GitHub Desktop.
Save maplebed/7755772 to your computer and use it in GitHub Desktop.
➜ export IFS='
'
:( ( 12/02/13@11:36AM )( maplebed@maplebook ):~/tmp
➜ args=($(ls -1)) 1
:) ( 12/02/13@11:36AM )( maplebed@maplebook ):~/tmp
➜ !echo
:) ( 12/02/13@11:36AM )( maplebed@maplebook ):~/tmp
➜ echo $args
file one file two four and five three
:) ( 12/02/13@11:36AM )( maplebed@maplebook ):~/tmp
➜ echo $args[1]
file one
:) ( 12/02/13@11:36AM )( maplebed@maplebook ):~/tmp
➜ for i in $args ; do echo $i ; done
file one
file two
four and five
three
:) ( 12/02/13@11:36AM )( maplebed@maplebook ):~/tmp
➜ cat $args
➜ for i in $args ; do echo "I am $i " > $i ; done
:) ( 12/02/13@11:37AM )( maplebed@maplebook ):~/tmp
➜ cat $args
I am file one
I am file two
I am four and five
I am three
@inexorabletash
Copy link

This matches my use case a little more closely:

commands=()
for i in "$@"; do
    b="this contains $i inside"
    commands+=('X')          # push command name
    commands+=("$i")         # push file name as one word
    commands+=("$b")         # push munged details as one word
done

function example()
{
    for var in "$@"; do
    echo "=> $var"
    done
}

flags="-a -b -c"

example $flags "${commands[@]}"  # one word per item

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment