B.Sc Computer Science
Linux and Shell Programming - Lab
Bharathiar University
Program 3. Write a Shell Script to implement the following: pipes, Redirection and tee commands
Source Code
# Demonstrate pipes
echo "Adding two numbers with use of pipes"
echo "Enter two numbers to perform addition:"
read a
read b
echo "Addition of $a and $b is:"
echo "$a + $b" | bc
echo
# Define a filename
filename="output.txt"
# Demonstrate redirection
echo "Redirection to output.txt file:" > $filename
echo "Hello, world!" >> $filename
echo "Goodbye, world!" >> $filename
echo "Contents of output.txt file:"
cat $filename
echo
# Demonstrate tee command
echo "Display and Writes to file using tee command:"
echo "Hai friend!" | tee -a $filename
echo "How are you?" | tee -a $filename
echo
# Display the contents of the file
echo "Contents of $filename after tee command:"
cat $filename
SAMPLE OUTPUT:
No comments:
Post a Comment