0

Sometimes (or may be all the time) an Alias and Function for a command works the same way. For example, following Alias and Function of Ping Command:

alias Pingoogle='ping -c 3 google.com && echo "internet working..."'
Pingoogle() {ping -c 3 google.com && echo "internet working...";}

works the same way by producing same output. But, My question is that in this situation which is more proper (or professional)? Setting Alias for such commands or Using Functions?

  • Good post. It means that using Alias is correct in my example. – Salman Ahmed May 07 '20 at 23:30
  • I would suggest a function, not an alias, for your example. As soon as you start writing shell syntax (like && or nested quotes) into your aliases it gets hard to reason about. Functions are much cleaner and you don't have to wrestle with escaping everything properly. – dimo414 May 08 '20 at 04:06

0 Answers0