fork download
  1. processLine(){
  2. line="$@" # get all args
  3. # just echo them, but you may need to customize it according to your need
  4. # for example, F1 will store first field of $line, see readline2 script
  5. # for more examples
  6. # F1=$(echo $line | awk '{ print $1 }')
  7. echo $line
  8. }
  9.  
  10. ### Main script stars here ###
  11. # Store file name
  12. FILE=""
  13.  
  14. # Make sure we get file name as command line argument
  15. # Else read it from standard input device
  16. if [ "$1" == "" ]; then
  17. FILE="/dev/stdin"
  18. else
  19. FILE="$1"
  20. # make sure file exist and readable
  21. if [ ! -f $FILE ]; then
  22. echo "$FILE : does not exists"
  23. exit 1
  24. elif [ ! -r $FILE ]; then
  25. echo "$FILE: can not read"
  26. exit 2
  27. fi
  28. fi
  29. # read $FILE using the file descriptors
  30.  
  31. # Set loop separator to end of line
  32. BAKIFS=$IFS
  33. IFS=$(echo -en "\n\b")
  34. exec 3<&0
  35. exec 0<"$FILE"
  36. while read -r line
  37. do
  38. # use $line variable to process line in processLine() function
  39. processLine $line
  40. done
  41. exec 0<&3
  42.  
  43. # restore $IFS which was used to determine what the field separators are
  44. IFS=$BAKIFS
Runtime error #stdin #stdout 0s 4596KB
stdin
Standard input is empty
stdout
Standard output is empty