Should I create an alias for each bash function? - Ask Ubuntu


i did short course on bash , terminal , 1 of best practices laid out in course creating alias each function created. example if had function:

function e() { echo "$*"; } 

i should create create alias:

alias e='e' 

do think makes sense , if yes reasoning? figure can source functions , use them without aliases anyway seems kind of unnecessary work.

case aliases

  • aliases can quite useful when want refer lengthy command short name.
  • in order of precedence, aliases stand higher functions, in case want override existing name for own session you'd use alias.

case functions

  • when have command requires dealing single , double quotes @ same time, use functions. deal sed or awk lot understand.
  • when want refer lengthy task consisting of multiple commands interacting variables, use function. in general , follow rule if there's more 3 commands, it's time use function.
  • aliases can escaped appending \. useful system administrators. if don't want user run command, function take precedence on . example:

    $ ls serg says command no-no $ \ls serg says command no-no 

    note user can still run /bin/ls no problems there, it's not security measure. i'd better use wrapper command, want add header or remove information.

  • from bash man page: there no mechanism using arguments in replacement text.if arguments needed, shell function should used. while can simple tricks - alias e="echo"; e hello - want function when want deal command-line arguments extensively.

in personal experience, found myself using functions far more aliases. scripts, except it's not necessary create external files - can live in ~/.bashrc. quoting , referencing variables become less of problem.


Comments

Popular posts from this blog

download - Firefox cannot save files (most of the time), how to solve? - Super User

windows - "-2146893807 NTE_NOT_FOUND" when repair certificate store - Super User