Last active
November 3, 2016 18:11
-
-
Save electrum/0d918d37dcb4b41fd2d78ec50989221c to your computer and use it in GitHub Desktop.
Bash variable expansion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
print '%s: %s' % (len(sys.argv) - 1, sys.argv[1:]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -eu | |
function go() { | |
echo "argc: $#" | |
./args.py $@ | |
./args.py "$@" | |
./args.py $* | |
./args.py "$*" | |
echo | |
} | |
echo "direct:" | |
./args.py $@ | |
./args.py "$@" | |
./args.py $* | |
./args.py "$*" | |
echo | |
shift | |
echo 'call $@' | |
go qqq $@ | |
echo 'call "$@"' | |
go qqq "$@" | |
echo 'call $*' | |
go qqq $* | |
echo 'call "$*"' | |
go qqq "$*" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./test.sh | |
direct: | |
4: ['abc', 'xyz', 'foo', 'bar'] | |
3: ['abc', 'xyz', 'foo bar'] | |
4: ['abc', 'xyz', 'foo', 'bar'] | |
1: ['abc xyz foo bar'] | |
call $@ | |
argc: 4 | |
4: ['qqq', 'xyz', 'foo', 'bar'] | |
4: ['qqq', 'xyz', 'foo', 'bar'] | |
4: ['qqq', 'xyz', 'foo', 'bar'] | |
1: ['qqq xyz foo bar'] | |
call "$@" | |
argc: 3 | |
4: ['qqq', 'xyz', 'foo', 'bar'] | |
3: ['qqq', 'xyz', 'foo bar'] | |
4: ['qqq', 'xyz', 'foo', 'bar'] | |
1: ['qqq xyz foo bar'] | |
call $* | |
argc: 4 | |
4: ['qqq', 'xyz', 'foo', 'bar'] | |
4: ['qqq', 'xyz', 'foo', 'bar'] | |
4: ['qqq', 'xyz', 'foo', 'bar'] | |
1: ['qqq xyz foo bar'] | |
call "$*" | |
argc: 2 | |
4: ['qqq', 'xyz', 'foo', 'bar'] | |
2: ['qqq', 'xyz foo bar'] | |
4: ['qqq', 'xyz', 'foo', 'bar'] | |
1: ['qqq xyz foo bar'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -eu | |
./args.sh abc xyz 'foo bar' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment