26 lines
562 B
Lua
26 lines
562 B
Lua
-- /bin/echo - Display contents of a text file.
|
|
local content_parts = {}
|
|
local filename = nil
|
|
local found_redirect = false
|
|
|
|
for i, v in ipairs(arg) do
|
|
if v == ">" then
|
|
found_redirect = true
|
|
filename = arg[i+1]
|
|
break
|
|
else
|
|
table.insert(content_parts, v)
|
|
end
|
|
end
|
|
|
|
if found_redirect then
|
|
if not filename then
|
|
return "echo: syntax error: expected filename after '>'"
|
|
end
|
|
local content = table.concat(content_parts, " ")
|
|
return { action = "write_file", target = filename, content = content }
|
|
else
|
|
return table.concat(arg, " ")
|
|
end
|
|
|