How/where can I save Bash scripts on my computer so that my terminal can execute more commands? -
terminal/bash has default set of commands, such cp, echo, grep,...
i'd able add command, "hello" can execute , result instead of -bash: hello: command not found.
you can add custom functions .bashrc or if mean actual stand-alone applications, make directory such ~/bin , add $path variable in .bash_profile or .profile , put stand-alone applications in said ~/bin directory.
greg's wiki pretty reliable source information on functions , other aspects of bash, along bash manual , bash hackers wiki.
note:
if have .profile can still use .bash_profile, if choose not use .bash_profile, please sure encapsulate code bash within if-statement since .profile used other shells:
if [ -n "$bash_version" ]; # bash_version defined, therefore using bash # bash code fi to simplify things create functions allowing run one-liners depending on shell you're running:
ifbash() { if [ -n "$bash_version" ]; $@ else return 1 fi } ifzsh() { if [ -n "$zsh_version" ]; $@ else return 1 fi } # can use these conditionally execute commands # here's function prints type/blueprint of function fn-printout() { y in "$@"; ifbash type "$y" || ifzsh whence -f "$y" done } (note: while using [ test ] not recommended when using bash, other shells may not understand [[ test ]]; 1 reason why better use .bash_profile, instead of .profile)
as pointed out in comments, while can define variables such $path in .bashrc, not recommended cause said variable re-set every time start interactive session of bash, resulting in unnecessary computational steps every time start new interactive session--it's better store variables , other environmental changes need happen once (such @ login) in .bash_profile, or .profile, can re-sourced needed using bash -l.
Comments
Post a Comment