0

I would like to make an alias for this command:

 grep 'world  ' FILE

where I want it to display all the lines containing 'world ' . The problem is that I cannot define it because the ' character is already used for defining the alias. Thus I cannot create an alias of command with something like this:

 alias name=' grep 'world  ' FILE 
  • 2
    The _easy_ answer is `alias name=$' grep \'world \' FILE`, but the _better_ answer is not to use an alias at all. Aliases don't let you do flow control; they make quoting more complicated; they can't be used in scripts without explicitly turning on off-by-default feature flags; they aren't guaranteed to be supported in POSIX-baseline shells; they don't show up in stack traces; they're otherwise worse than functions in every way. – Charles Duffy Nov 10 '20 at 16:34

1 Answers1

2

As in all things alias-related: Use a function instead.

name() { grep 'world  ' FILE "$@"; }
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441