#!/bin/bash
cat /var/backup/192.168.4.3/dirnum.prn | awk '{print $1}'
if i put above script can read the file.
#!/bin/bash
file1=/var/backup/192.168.4.3/dirnum.prn
exec <$file1
while read line
do
echo "$line"
done
but the above script can not read the file and gives error msg "The file or directory not found"
I am confused why its happening.Please help me.
Exec is supposed to read in a command and its arguments, you're just passing it a file. I would recommend (if you're set on using exec), to use cat as well.
If you're not set on using exec, I would recommend creating a variable (such as s_lines - prefixing it with the datatype (trust me, it makes the script easier to modify later if you need to)) and doing something like
s_lines=`cat $file1`
echo "$s_lines"
You can mess around with having the quotes or not. (Oh, and this is the Articles section. Not a big deal, but please be aware next time you post - to get in the Forum section!)