#!/bin/sh addarg() { args="$args $1" [ -z "$one" ] && one="$1" && return [ -z "$two" ] && two="$1" && return } for arg in "$@" do case "$arg" in param) param=1; ;; *) addarg "$arg" ;; esac shift; done echo "one=$one" echo "two=$two" echo "all=$args"