Skip to content

Instantly share code, notes, and snippets.

@wwalker
Created December 7, 2019 07:00
Show Gist options
  • Save wwalker/2086711615ffbcba144abe995c7bbda9 to your computer and use it in GitHub Desktop.
Save wwalker/2086711615ffbcba144abe995c7bbda9 to your computer and use it in GitHub Desktop.
harumph arg parser

I would expect to get

3 4 5 6
3 4 5 6

but the shifted parameters are still in place :-(

wwalker@serenity:~ ✓ $ ./a.sh 1 2 3 4 5 6
3 4 5 6
1 2 3 4 5 6
#!/bin/bash
arg_parser(){
shift
shift
POSITIONAL=()
while [[ $# -gt 0 ]]
do
POSITIONAL+=("$1")
shift
done
echo "${POSITIONAL[@]}"
set -- "${POSITIONAL[@]}"
}
arg_parser "$@"
echo "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment