Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- cat.lua
- -- Usage: cat <file> [file2 file3 ...]
- local args = { ... }
- if #args == 0 then
- print("Usage: cat <file> [file2 file3 ...]")
- return
- end
- for _, path in ipairs(args) do
- if not fs.exists(path) then
- printError("cat: " .. path .. ": No such file")
- elseif fs.isDir(path) then
- printError("cat: " .. path .. ": Is a directory")
- else
- local f = fs.open(path, "r")
- if not f then
- printError("cat: " .. path .. ": Could not open file")
- else
- while true do
- local line = f.readLine()
- if not line then break end
- print(line)
- end
- f.close()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment