And display the contents of the file in the stdout using #!/bin/bash
#!/bin/bash
echo"hello" >> ~/Hello
cat ~/Hello
should I use tee ~/Hello
to display contents of file Hello in stdout ?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityAnd display the contents of the file in the stdout using #!/bin/bash
#!/bin/bash
echo"hello" >> ~/Hello
cat ~/Hello
should I use tee ~/Hello
to display contents of file Hello in stdout ?
No, tee
is not for displaying the contents of a file. As with most *nix commands, you can see its manual by running man tee
. There, you will see:
NAME
tee - read from standard input and write to standard output and files
DESCRIPTION
Copy standard input to each FILE, and also to standard output.
So, tee
is used to write to files. The most common usage is to display text on screen and also save it to a file. For example:
echo "foo" | tee ~/bar
The command above will print foo
to your screen (standard output) and also save it to the file ~/bar
.
If you want to show the contents of a file, the standard way is precisely what you're doing: cat file
. So, cat ~/Hello
will show the contents of the file ~/Hello
.
By the way, you have a typo in your script. You want echo "hello"
not echo"hello"
.