Search code examples
bashgreppipekonsoleless-unix

Bash piping issue


I need to execute the following grep query as an argument for konsole (the kde terminal)

grep -R -i -n -A 2 -B 2 --color=always -R "searchtext" * | less -R

works for the current terminal.

konsole --workdir `pwd` -e grep -R -i -n -A 2 -B 2 --color=always -R "searchtext" * | less -R

works, but the konsole window displays the grep query without less pipe.

Ideally I want konsole to spawn as seperate process with konsole &

and send the grep command with less as an argument for konsole -e


Solution

  • You need to run the pipe in a shell.

    konsole --workdir pwd -e bash -c 'grep -R -i -n -A 2 -B 2 --color=always -R "searchtext" * | less -R'