diff --git a/srcenv b/srcenv index 81b1b1b..f818ea9 100755 --- a/srcenv +++ b/srcenv @@ -245,7 +245,7 @@ init() { bash|\ ksh|pdksh|mksh|\ posix|sh|\ - zsh) echo "$cmd() { eval \"\$($0 $shell --cmd \"$cmd\" $opts \"\$@\")\"; }" ;; + zsh) echo "$cmd() { eval \"\$($0 $shell $opts --cmd \"$cmd\" \"\$@\")\"; }" ;; csh|tcsh|\ elvish|\ fish|\ @@ -325,9 +325,10 @@ run() { setformat while [ $# -gt 0 ] && [ "$1" != -- ]; do + cmd= case $1 in - -c|--cmd) src=$(parse "$1" "$2") || exit $?; [ $# -gt 1 ] && shift; shift ;; - -c=*|--cmd=*) src=$(parse "${1%%=*}" "${1#*=}") || exit $?; shift ;; + -c|--cmd) src=$(parse "$1" "$2") || exit $?; [ $# -gt 1 ] && shift; cmd=1; shift ;; + -c=*|--cmd=*) src=$(parse "${1%%=*}" "${1#*=}") || exit $?; cmd=1; shift ;; -f|--format) value=$(parse "$1" "$2") || exit $?; [ $# -gt 1 ] && shift fmt "${value%\?\?*}" "${value#*\?\?}"; shift ;; @@ -373,7 +374,7 @@ run() { done if [ $# = 0 ]; then - if [ -n "$src" ]; then + if [ -n "$cmd" ]; then header; usage; desc; help; man; exit 0 elif [ -n "$backup" ] || [ -z "$restore" ]; then noinput; usage; help; exit 2 diff --git a/srcenv.tests b/srcenv.tests index 284c7ac..ac10504 100755 --- a/srcenv.tests +++ b/srcenv.tests @@ -551,7 +551,7 @@ run_posix_tests() { run "$1" "SRCENV_RESTORE='' $2 sh --restore" '' 5 run "$1" "$2 --restore" '' 2 run "$and_no_stdin" "$2 sh --backup --restore" '' 2 - run "$1" "$2 sh --cmd src --backup --restore" '' + run "$1" "$2 sh --backup --restore --cmd src" '' run "$1" "$2 sh --input 'echo something'" '' run "$1" "$2 sh --input 'echo something; not_a_command'" '' 127