Answers for "bash alias vs function vs script"

1

bash alias vs function vs script

Multiple ways of doing things but they differ,

alias:
- aliases are not available in shell scripts — for instance, 
in non-interactive shells
- limited bash functionaliy in here because of syntax

functions:
- functions available in the shell can be checked using the typeset command
- functions are more programmatic, and we can use loops and conditions within them. 
- functions can be made to output their source

If there’s something we do repetitively that’s too complex to be an alias, we should create a Bash function. 

script:
- anything goes here, full power

scripts should ideally be env independant and standalone
Posted by: Guest on March-07-2022

Browse Popular Code Answers by Language