Skip to content

Instantly share code, notes, and snippets.

@elundmark
Created July 17, 2019 11:09
Show Gist options
  • Save elundmark/5d3af1e8aa51f0ec8306c18a550f47a7 to your computer and use it in GitHub Desktop.
Save elundmark/5d3af1e8aa51f0ec8306c18a550f47a7 to your computer and use it in GitHub Desktop.
Print arguments on sepearate lines
#!/usr/bin/env bash
f() {
local -a args=("${@}") valid_args=()
local -i i=0 len=${#args[@]}
for (( ; i < len; i++ )); do
if [[ "${args[i]}" != '' ]] ; then
valid_args+=("${args[i]}")
else
echo "Removed empty string [$((i+1))]" 1>&2
fi
done
if (( ${#valid_args[@]} > 0 )) ; then
local IFS=$'\n'
echo "${valid_args[*]}"
fi
return $?
}
f "${@}"
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment