scripting

How to get Command history by cursor key in Linux tclsh

荒凉一梦 提交于 2020-12-29 02:45:26
问题 Can get the command history by using cursor key (like up arrow key) in TCL shell (tclsh). I am running tclsh on fedora with linux version 2.6.21. 回答1: You want access to the readline library, you can do that with rlwrap: $ rlwrap tclsh Useful options are -c for file name completion, and -f to add words from a file to the completion list: $ rlwrap -cf my_complete_file tclsh Since you almost always want to use rlwrap , adding a shell alias is useful: alias tclsh='rlwrap tclsh' 回答2: I usually

How to implement grep in bash scripting? [duplicate]

我的梦境 提交于 2020-12-13 18:14:13
问题 This question already has answers here : How to perform grep operation on all files in a directory? (5 answers) Closed 18 days ago . I am working on to search a string on files using grep in a directory(in for loop) for file in .* *; do if [[ -f "$file" && `grep -r "$pattern" "$file"` ]]; then path=`pwd`/"$file" echo "$path" fi done 回答1: Avoid the for loop and use something like grep -l "${pattern}" ${PWD}/.* ${PWD}/* or better find ${PWD} -type f -exec grep -l "${pattern}" {} + 回答2: Use find

How to implement grep in bash scripting? [duplicate]

倾然丶 夕夏残阳落幕 提交于 2020-12-13 17:57:15
问题 This question already has answers here : How to perform grep operation on all files in a directory? (5 answers) Closed 18 days ago . I am working on to search a string on files using grep in a directory(in for loop) for file in .* *; do if [[ -f "$file" && `grep -r "$pattern" "$file"` ]]; then path=`pwd`/"$file" echo "$path" fi done 回答1: Avoid the for loop and use something like grep -l "${pattern}" ${PWD}/.* ${PWD}/* or better find ${PWD} -type f -exec grep -l "${pattern}" {} + 回答2: Use find

How to implement grep in bash scripting? [duplicate]

◇◆丶佛笑我妖孽 提交于 2020-12-13 17:56:25
问题 This question already has answers here : How to perform grep operation on all files in a directory? (5 answers) Closed 18 days ago . I am working on to search a string on files using grep in a directory(in for loop) for file in .* *; do if [[ -f "$file" && `grep -r "$pattern" "$file"` ]]; then path=`pwd`/"$file" echo "$path" fi done 回答1: Avoid the for loop and use something like grep -l "${pattern}" ${PWD}/.* ${PWD}/* or better find ${PWD} -type f -exec grep -l "${pattern}" {} + 回答2: Use find

How can I determine if a variable exists from within the Groovy code running in the Scripting Engine?

此生再无相见时 提交于 2020-12-04 16:01:46
问题 How can I determine if a variable exists from within the Groovy code running in the Scripting Engine? The variable was put by ScriptEngine's put method 回答1: In the groovy.lang.Script there is a method public Binding getBinding() . See also groovy.lang.Binding with method public boolean hasVariable(String name) . Thus you can simple check variable existence like if (binding.hasVariable('superVariable')) { // your code here } 回答2: // Example usage: defaultIfInexistent({myVar}, "default") def

How can I determine if a variable exists from within the Groovy code running in the Scripting Engine?

你。 提交于 2020-12-04 16:00:39
问题 How can I determine if a variable exists from within the Groovy code running in the Scripting Engine? The variable was put by ScriptEngine's put method 回答1: In the groovy.lang.Script there is a method public Binding getBinding() . See also groovy.lang.Binding with method public boolean hasVariable(String name) . Thus you can simple check variable existence like if (binding.hasVariable('superVariable')) { // your code here } 回答2: // Example usage: defaultIfInexistent({myVar}, "default") def

Preserve environments vars after shell script finishes

▼魔方 西西 提交于 2020-11-28 04:54:54
问题 How can I keep the environment variables, set from a shell script, after the script finishes running? 回答1: This is not possible by running the script. The script spawns it's own sub-shell which is lost when the script completes. In order to preserve export s that you may have in your script, you can call them like this, which will add them to the current environment: . myScript.sh Notice the space between the . and the myScript.sh section. 回答2: run the script as follows: source <script> -OR-

Preserve environments vars after shell script finishes

五迷三道 提交于 2020-11-28 04:49:48
问题 How can I keep the environment variables, set from a shell script, after the script finishes running? 回答1: This is not possible by running the script. The script spawns it's own sub-shell which is lost when the script completes. In order to preserve export s that you may have in your script, you can call them like this, which will add them to the current environment: . myScript.sh Notice the space between the . and the myScript.sh section. 回答2: run the script as follows: source <script> -OR-

Preserve environments vars after shell script finishes

半城伤御伤魂 提交于 2020-11-28 04:49:43
问题 How can I keep the environment variables, set from a shell script, after the script finishes running? 回答1: This is not possible by running the script. The script spawns it's own sub-shell which is lost when the script completes. In order to preserve export s that you may have in your script, you can call them like this, which will add them to the current environment: . myScript.sh Notice the space between the . and the myScript.sh section. 回答2: run the script as follows: source <script> -OR-

Preserve environments vars after shell script finishes

随声附和 提交于 2020-11-28 04:48:30
问题 How can I keep the environment variables, set from a shell script, after the script finishes running? 回答1: This is not possible by running the script. The script spawns it's own sub-shell which is lost when the script completes. In order to preserve export s that you may have in your script, you can call them like this, which will add them to the current environment: . myScript.sh Notice the space between the . and the myScript.sh section. 回答2: run the script as follows: source <script> -OR-