On Sat, Nov 30, 2024 at 10:02:49AM +0000, Klemens Nanni wrote: > > + > > +Index: ejabberdctl.template > > +--- ejabberdctl.template.orig > > ++++ ejabberdctl.template > > +@@ -126,7 +126,7 @@ set_dist_client() > > + exec_cmd() > > + { > > + case $EXEC_CMD in > > +- as_install_user) su -s /bin/sh -c 'exec "$0" "$@"' "$INSTALLUSER" > > -- "$@" ;; > > ++ as_install_user) su -s /bin/sh "$INSTALLUSER" -c 'exec "$0" "$@"' > > "$@" ;; > > + as_current_user) "$@" ;; > > I don't understand why argv is passed twice, the one inside the -c string is > enough, no? > > Isn't $@ the whole command incl. argv[0] aka. $0? If so, 'exec_cmd echo foo' > would print > "echo foo" and not "foo" due to the 'exec $0'.
The outer $@ and inner $@ are different, and the one inside -c isn't expanded on the outer script. The first positional parameter after `sh -c '...'` will be assigned to $0, and the rest to $@. Passing `echo foo` will run `echo`.