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
sedorawklot 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-nonote user can still run
/bin/lsno 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
Post a Comment