TheDarBear

cat

Aug 20th, 2025
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. -- cat.lua
  2. -- Usage: cat <file> [file2 file3 ...]
  3.  
  4. local args = { ... }
  5. if #args == 0 then
  6. print("Usage: cat <file> [file2 file3 ...]")
  7. return
  8. end
  9.  
  10. for _, path in ipairs(args) do
  11. if not fs.exists(path) then
  12. printError("cat: " .. path .. ": No such file")
  13. elseif fs.isDir(path) then
  14. printError("cat: " .. path .. ": Is a directory")
  15. else
  16. local f = fs.open(path, "r")
  17. if not f then
  18. printError("cat: " .. path .. ": Could not open file")
  19. else
  20. while true do
  21. local line = f.readLine()
  22. if not line then break end
  23. print(line)
  24. end
  25. f.close()
  26. end
  27. end
  28. end
  29.  
Advertisement
Add Comment
Please, Sign In to add comment