Learn Advanced Bash by Building a Kitty Ipsum Translator - Difference between piping and redirecting here?

I am wondering if there is any meaningful difference between the results of running these two commands, one using piping and the other redirection. I got the exact same output in the terminal when running them, but the former was not accepted by the lesson, while the latter was:

cat name.txt | ./script.sh 
./script.sh < name.txt 

The first should read the contents of name.txt as stdout and pipe it as stdin into my script. The second redirects the contents of name.txt as the stdin of my script? Are those statements correct? Is the first one basically just the long way because there’s an extra step?

I was working on this step: It didn’t ask for input and nothing was printed in the terminal that time. You redirected both outputs to files. You should take a look at them to see if they have what you expected. Run your script again, use redirection to set name.txt as the input. Don’t redirect any of the output.

Lesson:

I don’t think you should get a different meaningful result. Even though both may produce the same output, the tests on the lesson may have been looking for you to use a specific command.

It seems like you already have a understanding of the concept. Piping passes the output of a command to another command. Redirection can handle the input and output of a single command, as well has pass the output to a file or stream.

2 Likes

Thanks for the response. This command line stuff is just a whole horse of a different breed than what I’m used to in other programming I’ve learned/am learning. I guess I just wanted to confirm I’m not missing something.

1 Like