path is the shell array variable that is tied to the PATH shell variable which is itself tied to the PATH environment variable.
When executing a command, all the memory of a process is wiped.
Environment variables are a way to pass data across execution. Like the command arguments, they are a list of NUL-delimited strings, but contrary to arguments, by convention:
- they take the form of
VAR=values
- commands (whether they're shells or anything else) remember the list of environment variable they received when they were executed, and pass them along to the commands they execute if they or their children do, so as to implement a form of inherited and inheritable environment. There is a standard C API (
putenv(), setenv(), unsetenv(), environ variable) to maintain that list of remembered env vars (the environ), and to execute commands, passing that list along (execl(), execvp()... which are wrappers around the execve() system call).
Shells specifically, in addition to doing that make up a variable in their language for some of the environment variables they receive and whose name is compatible with that of a shell variable. And the Bourne-like ones can promote a shell variable to an environment variable with the export builtin (other shells have equivalents).
csh, tcsh, zsh, yash, fish shells have ways to tie $PATH or other variables with :-separated values (generally environment ones such as PATH) to array variables.
For comparison, perl (also a programming language interpreter, but not a shell one) maps environment variables to its %ENV associative arrays (for example, the PATH environment variable is available in $ENV{PATH}), awk same with ENVIRON["PATH"], vim has $var for environment variables while it's just var for its own variables or @x for registers, etc.
To sum-up, environment variables, such as PATH are something that is universal and understood by everything and inherited (by convention) across execution.
There is no equivalent for shell aliases, which is a (poor) feature of some shells (not all) initially from csh, whose syntax varies from shell to shell, nor other data structures of any language.
Some shells such as rc and derivatives or bash can export their own function (also arrays in rc and derivatives), and to do that, they hijack environment variables, where the function definition is stored in a specific format, but only other instances of the same shell can load those variables from the environment and recreate the functions (or arrays) they encoded. Those variables don't make sense to other shells (or perl, vim, awk...) whose syntax is different anyway.
To be able to pass your list of zsh aliases to bash so equivalent bash aliases be created, you'd need to create code in the bash language which once evaluated would recreate those aliases. bash and zsh have some syntax in common, in particular the basic alias builtin syntax was copied in both from the Korn shell rather than csh, but zsh has added more features such as global aliases or suffix aliases and doesn't have the same limitations as bash when it comes to alias names, and bash ones can contain NULs in neither name nor value, so not all zsh aliases can be converted to bash aliases.
The quoting syntax is also different between the two shells, though they understand single quoting the same way (as long as rcquotes is not enabled in zsh). zsh makes the list of its plain aliases available in the $aliases special associative array, and like bash can dump a list of alias definitions with alias -L.
But in the latter, it does not always use single quoting, and could dump aliases whose name or values wouldn't work in bash, so you'd be better of looping over $aliases, filter out those that can't work in bash and do the quoting by hand (like with the qq parameter expansion flag).
.aliasesfile with your aliases and source it from the different shell rc files~/.bashrcso the exported value was being overwritten when I switched shells. My bad, thanks.bashshould keep the current exported environment variables" - But I didn't useexport, I used justpath+=..., right?path+=...is kind of converted toPATH=$PATH:...automatically; andPATHis exported by default by every shell, I think