lua-users home
lua-l archive

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


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