Skip to content

Instantly share code, notes, and snippets.

@minrk
Created February 23, 2018 16:01
Show Gist options
  • Save minrk/527a11b2442d7b3188ed7880cbda6d7c to your computer and use it in GitHub Desktop.
Save minrk/527a11b2442d7b3188ed7880cbda6d7c to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# show-args is a Python script that prints sys.argv[1:]
echo '$@ =' "$@"
echo 'no quotes: $@'
show-args $@
echo 'quotes: "$@"'
show-args "$@"
AT="$@"
echo 'quotes: "$AT" where AT="$@"'
show-args "$AT"
echo 'no quotes: $AT'
show-args $AT
echo "HOW DOES THAT WORK"
@mpacer
Copy link

mpacer commented Feb 23, 2018

Ah… i just realised I needed to add args after the invocation:
edit:
$ ./test.sh has space arg 2

and I needed to group the args to get the effect you're seeing:
$ ./test.sh "has space" "arg 2"

I got:

./test.sh "has space" "arg 2"
$@ = has space arg 2
no quotes: $@
['has', 'space', 'arg', '2']
quotes: "$@"
['has space', 'arg 2']
quotes: "$AT" where AT="$@"
['has space arg 2']
no quotes: $AT
['has', 'space', 'arg', '2']
HOW DOES THAT WORK

So it looks like I can reproduce… this is so weird.

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