220 posts
Location
Germany
Posted 30 January 2013 - 08:04 AM
Hello,
I know there are many posts about this, but I don't understand a single word, so I hope someone can explain me some stuff.
I want a program to check if in the startup file exists a line with "shell.run". (Anything can be behind it)
How is that possible?
537 posts
Location
Copenhagen, Denmark
Posted 30 January 2013 - 08:12 AM
You would do something like this:
local f = io.open("/startup", "r") -- open the startup file for reading
local data = f:read("*a") -- read the entire file
f:close() -- close the file
if data:find("shell.run") then -- check if "shell.run" exists in the file contents.
print("Found a line with shell.run!")
end
220 posts
Location
Germany
Posted 30 January 2013 - 08:17 AM
Thanks ~_~
537 posts
Location
Copenhagen, Denmark
Posted 30 January 2013 - 08:17 AM
Btw, it has nothing to do with splitting strings :)/>
220 posts
Location
Germany
Posted 30 January 2013 - 08:19 AM
xD Fail, well that's the only thing I found while searching for something like this…
1688 posts
Location
'MURICA
Posted 30 January 2013 - 08:20 AM
IIRC, :find() uses pattern matching, so you should probably escape that dot when looking for shell.run.
if data:find("shell%.run") then
537 posts
Location
Copenhagen, Denmark
Posted 30 January 2013 - 08:27 AM
Would be
if data:find("shell\.run") then
1054 posts
Posted 30 January 2013 - 08:37 AM
Would be
if data:find("shell\.run") then
No, patterns in lua are escaped with a %. It's not the same as escaping strings. It's just indicating that the character (dot) is not a magic symbol, but just a plain dot.