Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: alias with a parameter
2021-04-05 20:47:47 -0600, Grant Taylor:
[...]
> pd() {
> [ -n "${1}" ] && pushd "${1}" || popd;
> }
>
> It's using parameters on a function, just like you're trying to do. It
> works a treat.
>
> Aside: Yes, I'm lazy and don't want to type pushd or popd. Instead, the pd
> function determines which command to run based on if $1 is set or not.
[...]
That function would run popd when pushd fails. It's generally a
bad idea to use this kind of a && b || c in place of proper
if/then/else constructs.
pd() {
if [ "$#" -gt 0 ]; then
pushd "$@"
else
popd
fi
}
Or for the very lazy:
pd()if (($#)){pushd "$@"} else {popd}
--
Stephane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author