lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sun, Aug 15, 2010 at 04:02, Sean Conner <sean@conman.org> wrote:
> It was thus said that the Great James Graves once stated:
>> On Sun, Aug 15, 2010 at 11:17:35AM +0200, solyŽ wrote:
>>
>> > I have the following lua code
>> >
>> >
>> > act = {"dsm",   "nn10", "nn9"};
>> > for b = 1, table.getn(act), 1 do
>> > zz = act[b] ;
>> > os.execute("echo 'zz' >>\etc\putty\putty1.log")
>> > end
>> >
>> > i really want to add the value of the variable 'zz' in the echo
>> > command but the command os.execute("echo 'zz'
>> > >>\etc\putty\putty1.log") print the word zz not the value of the
>> > variable zz !!!
>> >
>> > plz help me to use the os.execute("echo to get the value of the
>> > variable zz in the file
>>
>> You can't just include the variable in the string.  Lua is not like
>> the shell interpreter.
>>
>> Instead, you want to concatenate the contents of the zz variable with
>> the rest of the string going into os.execute().
>>
>> So you want something like this instead:
>>
>>   os.execute("echo '" .. zz .. "' >>\etc\putty\putty1.log")
>
>  Alternatively, if you're just appending to the file, you can do:
>
>        act = { "dsm" , "nn10" , "nn9" }
>
>        -- open file in append mode
>        log = io.open("/etc/putty/putty1.log","a")
>
>        for b = 1 , #act do
>          log:write(act[b] .. "\n")
>        end
>
>        log:close()
>
>  And under Unix (or Linux most likely), the path seperator isn't '\' but
> '/'.  You can even use '/' under Windows (but not directly on the command
> line).
>
>  -spc
>
>

For that matter, if you are using \ as your directory separator, you
need to double it since it's the escape character. It might work in
this case but if you ever had a directory beginning with a special
character such as 'n', the '\n' would become a line break.

Windows supports using / as a separator, so you may as well just use
it all the time.

-- 
Sent from my toaster.