Skip to content

Instantly share code, notes, and snippets.

@snipsnipsnip
Created October 9, 2013 02:50
Show Gist options
  • Save snipsnipsnip/6895439 to your computer and use it in GitHub Desktop.
Save snipsnipsnip/6895439 to your computer and use it in GitHub Desktop.
nyaos.filter.quote_eval: bash-like $() style quote for nyaos
-- nyaos_filter_quote_eval.lua
-- bash風な逆クォートのカッコ版。ネスト可能。
-- 「echo $(echo bar $(echo foo))」は「bar foo」と出力される。
function nyaos.filter.quote_eval(cmdline)
return cmdline:gsub('%$(%b())', function(m)
local result, err = nyaos.eval(string.sub(m, 2, -2))
if err then
print('error in substitution: '..err)
return false
else
return result:gsub('^%s+', ''):gsub('%s+$', '')
end
end)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment