Skip to content

Instantly share code, notes, and snippets.

@travispaul
Last active August 3, 2019 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save travispaul/9688457044ab2473f15908b696cc9806 to your computer and use it in GitHub Desktop.
Save travispaul/9688457044ab2473f15908b696cc9806 to your computer and use it in GitHub Desktop.
Setting a default value for $@ (sh vs dash vs ksh vs bash)
#!/bin/sh
#!/bin/ksh
#!/usr/pkg/bin/dash
#!/usr/pkg/bin/bash
somefn() {
local args="${@:-something}"
echo "Value of \$args: $args"
}
# prints "something"
somefn
# prints "foo" in every shell but bash, where it prints "foo bar"
somefn foo bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment