eval

Properly handling spaces and quotes in bash completion

狂风中的少年 提交于 2019-11-28 06:49:46
What is the correct/best way of handling spaces and quotes in bash completion? Here’s a simple example. I have a command called words (e.g., a dictionary lookup program) that takes various words as arguments. The supported ‘words’ may actually contain spaces, and are defined in a file called words.dat : foo bar one bar two Here’s my first suggested solution: _find_words() { search="$cur" grep -- "^$search" words.dat } _words_complete() { local IFS=$'\n' COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" COMPREPLY=( $( compgen -W "$(_find_words)" -- "$cur" ) ) } complete -F _words_complete words

In C# is there an eval function?

寵の児 提交于 2019-11-28 06:37:22
I'm typing an equation into a textbox that will generate the graph of the given parabola. Is it possible to use an eval function? My C# 2010 doesn't have microsoft.jscript . C# doesn't have a comparable Eval function but creating one is really easy: public static double Evaluate(string expression) { System.Data.DataTable table = new System.Data.DataTable(); table.Columns.Add("expression", string.Empty.GetType(), expression); System.Data.DataRow row = table.NewRow(); table.Rows.Add(row); return double.Parse((string)row["expression"]); } Now simply call it like this: Console.WriteLine(Evaluate(

eval in Objective-C [duplicate]

扶醉桌前 提交于 2019-11-28 06:24:08
问题 Possible Duplicate: Is there something like Matlab's eval statement in Objective-C 2.0? Is there an eval function (as in lisp, javascript, python, ruby...) in Objective-C? What I mean by eval is a function that can take in arbitrary Objective-C code (possibly having class definitions, side effects, instrospection, etc) as a string (not a block or an NSInvocation or IMP or something like that), and evaluate each expression, respecting the current runtime environment state, side effects, class

Ruby: creating a sandboxed eval?

烂漫一生 提交于 2019-11-28 06:24:02
My Rails app has complicated rules about when a bit of content should be displayed on a page or not. I've decided to implement this by writing predicates (simple 'yes/no' functions) in Ruby and storing them in the db for subsequent eval'ing. It it pretty straightforward. My main concern is security: if a malicious somebody figures out how to write to the db, they could stick arbitrary Ruby code in the db and then ' all your base are belong to us '. So is it possible to create an 'sandboxed' eval, for example, which has all IO operations removed? Pablo Fernandez You might want to check the

Shell 中eval的用法

戏子无情 提交于 2019-11-28 06:05:00
test.sh: pipe="|" eval ls $pipe wc -l 输出 bogon:Desktop macname$ ./test.sh 45 test.sh: eval echo \$$# 输出 bogon:Desktop macname$ ./test.sh ssd dede ded dedeeeee iiii iiii 参考: https://blog.csdn.net/luliuliu1234/article/details/80994391 来源: https://www.cnblogs.com/sea-stream/p/11396291.html

eval javascript, check for syntax error

两盒软妹~` 提交于 2019-11-28 05:43:36
I wanted to know if it is possible to find through javascript if a call to eval() has a syntax error or undefined variable, etc... so lets say I use eval for some arbitrary javascript is there a way to capture the error output of that eval? You can test to see if an error is indeed a SyntaxError. try { eval(code); } catch (e) { if (e instanceof SyntaxError) { alert(e.message); } } When using try catch for catching particular type of error one should ensure that other types of exceptions are not supressed. Otherwise if evaluated code would throw a different kind of exception it could disappear

在jsp页面解析jsonarray

你说的曾经没有我的故事 提交于 2019-11-28 05:08:17
在jsp页面解析jsonarray 首先需要将后台传过来的json串转成json对象: jsonData=eval("("+data+")"); //或者 var jsonData = eval(data); 然后将该json对象循环遍历将其中的数据取出来 1、什么是eval函数 eval()是一个函数,有且只有一个参数string,为字符串类型 eval(string) 特点:若string为js代码时,会直接解析执行,若是普通字符串,则返回原字符串。 2、eval解析json数据 错误实例: var jsonstr = "{name:'test',age:18}"; var jsonobj = eval(jsonstr);//拼接过程 3、错误提示: SyntaxError: invalid label 为什么会这样? 原因在于:eval本身的问题。 由于json是以”{}”的方式来开始以及结束的,在JS中,它会被当成一个语句块来处理,所以必须强制性的将它转换成一种表达式。 加上圆括号的目的是迫使eval函数在处理JavaScript代码的时候强制将括号内的表达式(expression)转化为对象,而不是作为语句 (statement)来执行。 4、如何解决? var josnobj = eval("("+jsonstr+")"); 或者这样 eval("var jsonobj

Eval not working on multi-line string

允我心安 提交于 2019-11-28 05:06:41
问题 I am having issues with executing a multi-line string with the python eval function/ code = ''' def main(): print "this is a test" main() ''' eval(code) Traceback (most recent call last): File "<pyshell#12>", line 1, in <module> eval(code) File "<string>", line 3 def main(): ^ SyntaxError: invalid syntax 回答1: eval can only evaluate Python expressions, not statements. A function definition is a statement, not an expression. Use exec to execute Python statements. See the Top-level components

Javascript calling eval on an object literal (with functions)

牧云@^-^@ 提交于 2019-11-28 04:13:17
问题 Disclaimer: I fully understand the risks/downsides of using eval but this is one niche case where I couldn't find any other way. In Google Apps Scripting, there still is no built-in capability to import a script as a library so many sheets can use the same code; but, there is a facility built-in where I can import text from a plaintext file. Here's the eval-ing code: var id = [The-docID-goes-here]; var code = DocsList.getFileById(id).getContentAsString(); var lib = eval(code); Logger.log(lib

Python 可执行对象

雨燕双飞 提交于 2019-11-28 03:58:37
Python 可执行对象 eval/repr eval eval 可以执行字符串类型的表达式 (或 compile() 创建的代码对象(code object) ) 并返回执行结果 eval(expression, globals=None, locals=None) expression 参数会作为一个 Python 表达式被解析并求值 globals 和 locals 作为全局和局部命名空间,globals 实参必须是一个字典,locals 可以是任何映射对象。 默认为当前环境,如果只给了 globals,则默认 locals 与 globals 相同 repr 返回一个对象的字符串形式返回值,通过这个字符串可以重新获取该对象,因为对于许多对象类型 eval(repr(obj)) == obj 成立 类可以通过定义 __repr__() 方法来控制此函数为它的实例所返回的内容 exec exec 支持动态执行 Python 代码,返回值是 None exec(object, globals=None, locals=None) object 为字符串时,会被解析成 Python 语句执行,为代码对象时会被直接执行 globals 和 locals 作为全局和局部命名空间,globals 实参必须是一个字典,locals 可以是任何映射对象。 默认为当前环境 compile