Quantcast
Channel: grep with heredoc in function - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 4

Answer by Stéphane Chazelas for grep with heredoc in function

$
0
0
alias 'gsi=<<eof grep --color'

Would work as alias is just like preprocessor text replacement, where the replacement is interpreted as shell code again.

Yours was not working as you had that "$1". With gsi file.txt replaced with cat <<eof | grep --color "$1" file.txt, then the shell carries on interpreting that command line and $1 at that point is the shell's first positional parameter which is probably empty unless you did a set something beforehand. So you'd want to remove that "$1" here. You can remove the UUOC as well.

gsi() { cat <<eof | grep --color "$1" ; }

is wrong from a syntax point of view as the eof line is missing after that cat <<eof.


Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>