For some reason (?), often when I write scripts nowadays they do not work, or work only in part, and then I try with .
or source
and they work perfectly. I'm unsure what is causing this as the scripts are different in a lot of ways, it's hard to isolate what must be sourced in order for the script as a whole to work. Also, I've noticed that this is almost always the case when I move things from .bashrc
aliases and functions into scripts.
But to my actual question, in the above situation, what is the optimal way to "swallow" the source dot, so you are still able to use the scripts as one-word commands, not having to hit the dot every time?
.
are NOT valid reasons to choose one over the other, and conflating the syntax will probably break many things. Once you understand the differences between functions, scripts, and sourced scripts, come back and describe what you are really trying to do. – jw013 Sep 10 '12 at 20:16.
is not that hard to type. Or, make a function:script () { . script; }
and use that instead. – jw013 Sep 10 '12 at 20:17type
; and 2) (most important) if I edit a script and run it, it's there, I don't have to remember sourcing.bashrc
(or whatever file). Perhaps that's another question, but if you know how to do that for functions, I'm convinced. As for the link, that's an awesome thread, but it is more about doing it right from day one (or from now on), this (my question) is more fixing a situation that has occurred. – Emanuel Berg Sep 11 '12 at 01:28.bashrc
- if you put all (and any new) such "function scripts" in a single directory, you don't even have to mention them explicitly in.bashrc
. But, the other drawbacks I mentioned are still there - no tracking (at least not withtype
) and you have to source.bashrc
all over after update. (Actually, I'm very happy with jw013's solution.) I'm sure zsh is great, only I'd like to stick with the most common Unix-world choices as to remain mobile myself. – Emanuel Berg Sep 13 '12 at 02:08