Reputation: 11
I was reading through a bash script that takes an input and check if the there's a topic on the input word. At first, the list of available topics was created in the script from the lines of code below below.
echo "On which topic do you want advice?"
cat << topics
politics
startrek
kernelnewbies
sports
bofh-excuses
magic
love
literature
drugs
education
topics
Based on my understanding, cat can take input from stdin or piping and redirect it to stdout
cat
now
now
later
later
or redirect/append the input to a file content
cat >> file.txt
Does cat take input from stdin an redirect it back to stdin? Also, why does topic have to appear twice in the first code block? Is it a wrapper or some sort of stdin copy/imitation?
I tried to see if there would be the file "topics" would be created in the directory, but there was nothing related to it existence or the input list of words in the working directory.
Upvotes: 0
Views: 222
Reputation: 69208
what you see first is the echo from your terminal, when you press RETURN, cat
receives the input you typed (stdin) and copies it to the output (stdout).
If you run
stty -echo; cat; stty echo
which disables local echo, runs cat
(until EOF, usually ^D
), and the re-enabled echo, you will see what you type only once.
Upvotes: 1