In Bourne-like shells, "$1"
expands to the first argument of the function (or of the script if not expanded inside a function) or to the empty string if not, "$2"
would be the second, "$3"
third... "${10}"
tenth¹, "$@"
expands to all supplied arguments.
${1+"$1"}
expands to the first argument if supplied and nothing (not even an empty string) if not. So ${1+"$1"} ${2+"$2"}
would expand to up to 2 of the first arguments of the function. In the yash
or zsh
shells, that can be simplified to "${@[1,2]}"
(even to "$@[1,2]"
in zsh
), and in ksh93
, bash
and zsh
to "${@:1:2}"
.
pip39() {python3.9 -m pip "$1"}
is zsh syntax however. In bash
or other Bourne-like shell, you'd need pip39() { python3.9 -m pip "$1";}
(or simply pip39() python3.9 -m pip "$1"
in the Bourne shell and most Bourne-like shells, though not bash, posh nor yash).
So here, in bash (as you tagged your question) or zsh (as in the syntax of the code in your question), you'd want:
pip39(){ python3.9 -m pip "$@";}
To pass all the arguments of pip39
to python3.9
, that code being Bourne and POSIX compatible.
Or to pass only a limited number of arguments (here 3 as an example):
pip39(){ python3.9 -m pip "${@:1:3}"; } # ksh93, bash, zsh
pip39(){ python3.9 -m pip "${@[1,3]}"; } # zsh, yash
pip39(){ python3.9 -m pip ${1+"$1"} ${2+"$2"} ${3+"$3"}; } # any Bourne-like shell
¹ Not in the Bourne shell where you're limited to 9. $10
would be either like ${10}
or ${1}0
depending on the shell (POSIX requiring the latter unfortunately) so should be avoided.
alias pip39='python3.9 -m pip'
) all you need?alias
take arguments? I dont know , I will try thatpip39
withpython3.9 -m pip
in the command line. Since the arguments simply follow that, it seems sufficient for your case.