Advertisement
sanovskiy

lua cat

Aug 16th, 2014
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.56 KB | None | 0 0
  1. local args = { ... }
  2. local file = nil
  3.  
  4. if #args > 1 then
  5.   print("Usage: cat [file]")
  6.   return
  7. end
  8.  
  9. if #args == 1 then
  10.   local f = args[1]
  11.  
  12.   if not fs.exists(f) then
  13.         print("cat: " .. f .. ": No such file")
  14.         return
  15.   end
  16.  
  17.   if fs.isDir(f) then
  18.         print("cat: " .. f .. ": Is a directory")
  19.   end
  20.  
  21.   file = fs.open(f, 'r')
  22. end
  23.  
  24. local line = nil
  25.  
  26. while true do
  27.   if file ~= nil then
  28.         line = file.readLine()
  29.   else
  30.         line = read()
  31.   end
  32.  
  33.   if line ~= nil then
  34.         print(line)
  35.   else
  36.         return
  37.   end
  38. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement