Skip to content

Instantly share code, notes, and snippets.

@mitsu-ksgr
Created November 15, 2018 22:00
Show Gist options
  • Select an option

  • Save mitsu-ksgr/d49c2407f8a55ed799b164a8c2da14dc to your computer and use it in GitHub Desktop.

Select an option

Save mitsu-ksgr/d49c2407f8a55ed799b164a8c2da14dc to your computer and use it in GitHub Desktop.
bash shift example
#!/bin/sh
set -e
#------------------------------------------------------------------------------
# shift sample
#
#
# $ ./shift.sh a b c [shell]
# > ARGV: 3, ARGS: [a b c], Shifted: [b c]
# > ARGV: 2, ARGS: [b c], Shifted: [c]
# > ARGV: 1, ARGS: [c], Shifted: []
# > ARGV: 0, ARGS: [], finish!
#------------------------------------------------------------------------------
echo -n "ARGV: $#, ARGS: [$*]"
if [ -z "$1" ]; then
echo ", finish!"
else
shift
echo ", Shifted: [$*]"
. ./test.sh $*
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment