1

Bash functions are more versatile than aliases. For example, they accept parameters.

Is there any drawback to going full function style and completely drop aliases, even for simple cases? I can imagine that maybe functions are more resource intensive, but have no data to back that up.

Any other reason to keep some of my aliases? They have easier syntax and are easier for humans to read, but apart from that?

Community
  • 1
  • 1
blueFast
  • 41,341
  • 63
  • 198
  • 344
  • I just think that aliases are easy to set up maintain in simple instances. Not sure that there is a resource over as such. – Raman Sailopal May 09 '17 at 10:16
  • alias may be use only in command line to shorten the commands whereas functions are used in scripts and are more powerful, aliases will not work by default in scripts, in script the readability will be more important. – Nahuel Fouilleul May 09 '17 at 10:27

1 Answers1

1

Note: aliases take precedence over functions.

Following link may be relevant regarding function overhead, it seems there is no overhead comparing to alias: 3.6. Functions, Aliases, and the Environment

Quoting Dan again: "Shell functions are about as efficient as they can be. It is the approximate equivalent of sourcing a bash/bourne shell script save that no file I/O need be done as the function is already in memory. The shell functions are typically loaded from [.bashrc or .bash_profile] depending on whether you want them only in the initial shell or in subshells as well. Contrast this with running a shell script: Your shell forks, the child does an exec, potentially the path is searched, the kernel opens the file and examines enough bytes to determine how to run the file, in the case of a shell script a shell must be started with the name of the script as its argument, the shell then opens the file, reads it and executes the statements. Compared to a shell function, everything other than executing the statements can be considered unnecessary overhead."

Nahuel Fouilleul
  • 18,726
  • 2
  • 31
  • 36