variables

How do I store a command in a variable and use it in a pipeline? [duplicate]

拜拜、爱过 提交于 2020-01-23 03:27:25
问题 This question already has answers here : Why does shell ignore quotes in arguments passed to it through variables? [duplicate] (3 answers) Closed 3 years ago . If i use this command in pipeline, it's working very well; pipeline ... | grep -P '^[^\s]*\s3\s' But if I want to set grep into variable like: var="grep -P '^[^\s]*\s3\s'" And if I put variable in pipeline; pipeline ... | $var nothing happens, like there isn't any matches. Any help what am I doing wrong? 回答1: The robust way to store a

Passing unset variables to functions

可紊 提交于 2020-01-23 01:14:46
问题 My code: function Check($Variable, $DefaultValue) { if(isset($Variable) && $Variable != "" && $Variable != NULL) { return $Variable; } else { return $DefaultValue; } } $a = Check(@$foo, false); $b = Check(@$bar, "Hello"); //$a now equals false because $foo was not set. //$b now equals "Hello" because $bar was not set. When a variable doesn't exist and is passed to the function (suppressing the error) what is actually passed? Is there any undefined behaviour that this function could exhibit?

If you can't change a variable's value in Haskell, how do you create data structures?

拜拜、爱过 提交于 2020-01-22 05:50:05
问题 As per the title. I have the following code which creates a binary search tree, but if I want it created and changed dynamically with user input, how would I do that if I can't change the value of a variable in haskell?!? find :: (Ord a) => Node a -> a -> Bool find (Node val left right) s | s == val = True | s < val = find left s | s > val = find right s find Empty s = False data Node a = Node a (Node a) (Node a) | Empty myTree = Node "m" (Node "a" Empty Empty) (Node "z" Empty Empty) Thanks

Makefile variable initialization and export

女生的网名这么多〃 提交于 2020-01-22 05:48:04
问题 somevar := apple export somevar update := $(shell echo "v=$$somevar") all: @echo $(update) I was hoping to apple as output of command, however it's empty, which makes me think export and := variable expansion taking place on different phases. how to overcome this? 回答1: The problem is that export exports the variable to the subshells used by the commands; it is not available for expansion in other assignments. So don't try to get it from the environment outside a rule. somevar := apple export

How to base64 encode image in linux bash / shell

和自甴很熟 提交于 2020-01-22 04:12:32
问题 I'm trying to base64 encode an image in a shell script and put it into variable: test="$(printf DSC_0251.JPG | base64)" echo $test RFNDXzAyNTEuSlBH I've also tried something like this: test=\`echo -ne DSC_0251.JPG | base64\` but still with no success. I want to do something like this: curl -v -X POST -d '{"image":$IMAGE_BASE64,"location":$LOCATION,"time_created":$TIMECREATED}' -H 'Content-type: text/plain; charset=UTF8' http://192.168.1.1/upload I found this http://www.zzzxo.com/q/answers

How to base64 encode image in linux bash / shell

心不动则不痛 提交于 2020-01-22 04:12:26
问题 I'm trying to base64 encode an image in a shell script and put it into variable: test="$(printf DSC_0251.JPG | base64)" echo $test RFNDXzAyNTEuSlBH I've also tried something like this: test=\`echo -ne DSC_0251.JPG | base64\` but still with no success. I want to do something like this: curl -v -X POST -d '{"image":$IMAGE_BASE64,"location":$LOCATION,"time_created":$TIMECREATED}' -H 'Content-type: text/plain; charset=UTF8' http://192.168.1.1/upload I found this http://www.zzzxo.com/q/answers

Beginner Java: Variable Scope Issue

纵然是瞬间 提交于 2020-01-22 03:48:09
问题 I'm practicing some work from my java book and I'm having an issue with getting a method to use a variable for a calculation. Please note that this is a work in progress and I'm only trying to get it to use the circleArea method to calculate the area of a circle at the moment. Here is the necessary code: public class Geometry { public static void printMenu() { System.out.println("This is a geometry calculator\nChoose what you would like to calculate" + "\n1. Find the area of a circle\n2. Find

capture change of global variable value in python

守給你的承諾、 提交于 2020-01-21 12:16:48
问题 How do i detect or capture change of value of a global variable in python variable = 10 print(variable) variable = 20 # Detect changes to the value using a signal to trigger a function UPDATE AST docs - GOOD INTRO https://greentreesnakes.readthedocs.io/en/latest/ 回答1: To my knowledge, it is not possible to generically capture the assignment of a global symbol in Python (At least in CPython where globals are stored in a dict in the module object, both are C types that cannot be monkey patched)

how to calculate 95th percentile of values with grouping variable in R or Excel

我只是一个虾纸丫 提交于 2020-01-21 11:02:11
问题 i'm trying to calculate the 95th percentile for multiple water quality values grouped by watershed. for example... Watershed WQ 50500101 62.370661 50500101 65.505046 50500101 58.741477 50500105 71.220034 50500105 57.917249 i reviewed this question posted - Percentile for Each Observation w/r/t Grouping Variable. it seems very close to what i want to do but it's for EACH observation. i need it for each grouping variable. so ideally, Watershed WQ - 95th 50500101 x 50500105 y thanks 回答1: This

How to use variables defined in a public class in other classes in java?

南笙酒味 提交于 2020-01-21 09:49:09
问题 A layman's question on the definition and use of variables: I need to make a Java GUI that gets user's input and stores it within a text file. However this writing has to be done inside an Actionlistener class (ie, user is clicking the button and text file is created and stored). This means that I have to define a variable in one class (public class) and use it in another (the one that defines the Actionlistener). How can I do this? Are global variables the only way? In my code I first define