Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Piping echo output to another echo

Tags:

bash

shell

echo

Is there any way to pipe echo output to another echo and slice it without using variable?

For example: This can be done without using pipe

var="heyyy hello there HRU?"
echo "${var:11}"

But we don't use var while using pipe...

echo "heyyy hello there HRU?" | echo "${?:11}"

How to capture the output from previous command and slice it as we use do using variable? Is there any way to do it?

I know it can be done using multiple commands like "sed", "awk", "cut", etc., but I just wanted to know if there any way to do it with echo.

like image 255
Raj Avatar asked Nov 26 '25 12:11

Raj


2 Answers

Capture it in a variable.

echo "heyyy hello there HRU?" | { var=$(cat); echo "${var:11}"; }
like image 119
KamilCuk Avatar answered Nov 29 '25 09:11

KamilCuk


echo doesn't use stdin !. It can just print arguments given to it. So what you're trying won't work in short.

echo -- write arguments to the standard output

Refer Man Page : https://man7.org/linux/man-pages/man1/echo.1p.html

STDIN
       Not used.
like image 41
Akshay Hegde Avatar answered Nov 29 '25 09:11

Akshay Hegde



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!