Bash 3 syntax and slight adjustments mostly for code style

This commit is contained in:
Tyler Akins 2016-07-21 09:34:02 -05:00
parent ade7c1e77b
commit 2888626334

17
mo
View File

@ -23,15 +23,16 @@
# $* - Filenames to parse. Can use -h or --help as the only option # $* - Filenames to parse. Can use -h or --help as the only option
# in order to show a help message. Additionaly, --source=file # in order to show a help message. Additionaly, --source=file
# can be passed so that mo sources the file before parsing # can be passed so that mo sources the file before parsing
# the filenames. # the filenames
# #
# Returns nothing. # Returns nothing.
mo() ( mo() (
# This function executes in a subshell so IFS is reset. # This function executes in a subshell so IFS is reset.
# Namespace this variable so we don't conflict with desired values. # Namespace this variable so we don't conflict with desired values.
local moContent files=() local moContent f2source files
IFS=$' \n\t' IFS=$' \n\t'
files=()
if [[ $# -gt 0 ]]; then if [[ $# -gt 0 ]]; then
for arg in "$@"; do for arg in "$@"; do
@ -42,19 +43,19 @@ mo() (
;; ;;
--source=*) --source=*)
local f2source="${1#--source=}" f2source="${1#--source=}"
if [[ -f "$f2source" ]]; then if [[ -f "$f2source" ]]; then
. "$f2source" . "$f2source"
continue
else else
printf "%s: %s: %s\n"\ echo "No such file: $f2source" >&2
"$0" "$f2source" "No such file" >&2
exit 1 exit 1
fi fi
;; ;;
*) # Every arg that is not a flag or a option should be a file *)
files+=("$arg") # Every arg that is not a flag or a option should be a file
files=("${files[@]}" "$arg")
;; ;;
esac esac
done done