Contents of emp1.sh
script
#!/bin/bash
#emp1.sh: interactive version uses read to take input
echo "Enter the pattern to be searched: \c"
read pname
echo "Enter the file to be used: \c"
read flname
echo "searching for the pattern $pname from the file $flname"
grep "$pname" $flname
echo "Selected records are shown above"
Why there is a difference between the outputs?
$ sh emp1.sh
Enter the pattern to be searched:
$ ./emp1.sh
Enter the pattern to be searched: \c
printf
should be used instead ofecho
. As a bash script,read
's -p should be used instead ofecho
. E.g.read -ep "Enter file to be used: " flname