File Not found Error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shathil
    New Member
    • Jul 2007
    • 1

    File Not found Error

    #!/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.Pleas e help me.
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Originally posted by shathil
    #!/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.Pleas e 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!)

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by sicarie
      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!)
      Moved to forum section

      Comment

      Working...