Skip to content

Instantly share code, notes, and snippets.

@progrium
Last active August 29, 2015 14:01

Revisions

  1. progrium revised this gist May 29, 2014. 1 changed file with 13 additions and 1 deletion.
    14 changes: 13 additions & 1 deletion gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -7,4 +7,16 @@ destructuring_assignment_for_named_local_args() {
    echo "$words"
    }

    destructuring_assignment_for_named_local_args 123 abc "Hello world"
    destructuring_assignment_for_named_local_args 123 abc "Hello world"

    # Actually, for local args, this is still probably preferrable:

    declare_named_local_args() {
    declare numbers="$1" letters="$2" words="$3"

    echo "$numbers"
    echo "$letters"
    echo "$words"
    }

    declare_named_local_args 123 abc "Hello world"
  2. progrium revised this gist May 29, 2014. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,10 @@
    destructuring_assignment_for_named_local_args() {
    declare foo bar baz
    read foo bar baz <<<"$@"
    declare numbers letters words
    read numbers letters words <<<"$@"

    echo "$foo"
    echo "$bar"
    echo "$baz"
    echo "$numbers"
    echo "$letters"
    echo "$words"
    }

    destructuring_assignment_for_named_local_args 123 "Foobar" baz
    destructuring_assignment_for_named_local_args 123 abc "Hello world"
  3. progrium revised this gist May 29, 2014. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,10 @@
    destructuring_assignment_for_named_local_args() {
    declare foo bar baz
    read foo bar baz <<<$@
    read foo bar baz <<<"$@"

    echo $foo
    echo $bar
    echo $baz
    echo "$foo"
    echo "$bar"
    echo "$baz"
    }

    destructuring_assignment_for_named_local_args 123 "Foobar" baz
  4. progrium revised this gist May 29, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    destructuring_assignment_for_named_local_args() {
    declare foo bar baz
    read foo bar baz <<<$@

    echo $foo
    echo $bar
    echo $baz
  5. progrium revised this gist May 29, 2014. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    destructuring_assignment_for_named_local_args() {
    declare foo bar baz; read foo bar baz <<<$@
    declare foo bar baz
    read foo bar baz <<<$@
    echo $foo
    echo $bar
    echo $baz
  6. progrium renamed this gist May 29, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  7. progrium created this gist May 29, 2014.
    8 changes: 8 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    destructuring_assignment_for_named_local_args() {
    declare foo bar baz; read foo bar baz <<<$@
    echo $foo
    echo $bar
    echo $baz
    }

    destructuring_assignment_for_named_local_args 123 "Foobar" baz