I am using Laravel 5.4 and vlucas/phpdotenv library.
I wants to take reference of one env variable to other env variable e.g.
APP_NAME: JUSTDOIT
SIGNUP_KEY: JUSTDOIT_SIGNUP
here in SIGNUP_KEY I wants to use whatever APP_NAME it is.
Ahh, I found the answer here, Not removing the question as it may help to other,
It's possible to nest an environment variable within another, useful to cut down on repetition.
This is done by wrapping an existing environment variable in ${…} e.g.
APP_NAME: JUSTDOIT
SIGNUP_KEY: ${APP_NAME}_SIGNUP
additionally if you wants to use space in variable value then encluse this with "quotes" e.g.
SIGNUP_KEY: "${APP_NAME} SIGNUP"
Reference:
https://github.com/vlucas/phpdotenv#nesting-variables
Related
How can I export an environment variable like this?
USERS=[{name:a,surname:b,age:c},{name:d,surname:e,age:f}]
What I've tried so far unsuccessfully
[{"name":"a","surname":"b","age":"c"},{"name":"d","surname":"e","age":"f"}]
[{'name':'a','surname':'b','age':'c'},{'name':'d','surname':'e','age':'f'}]
[{\'name\':\'a\',\'surname\':\'b\',\'age\':\'c\'},{\'name\':\'d\',\'surname\':\'e\',\'age\':\'f\'}]
[{\"name\":\"a\",\"surname\":\"b\",\"age\":\"c\"},{\"name\":\"d\",\"surname\":\"e\",\"age\":\"f\"}]
"[{"name":"a","surname":"b","age":"c"},{"name":"d","surname":"e","age":"f"}]"
'[{"name":"a","surname":"b","age":"c"},{"name":"d","surname":"e","age":"f"}]'
'[{'name':'a','surname':'b','age':'c'},{'name':'d','surname':'e','age':'f'}]'
I know that with docker-compose and terraform this can easily be done but I have to define a single env var here
Something very important that I forgot to mentioned:
I want this variable to be read as a LIST since it's part of a configuration file. Not as a string. Since I want to map it to a User object.
User {
name,
surname,
age
}
Put it in quotes and use the export command to put it in the environment. Also, make it valid JSON by quoting all the strings
export USERS='[{"name":"a","surname":"b","age":10},{"name":"d","surname":"e","age":35}]'
Is it possible to concatenate a string to call a Bamboo variable.
Using a script task in Bamboo, I want to generalize the following:
python my.py moon ${bamboo.mynamespace.moon}
to
SET planet=MOON
python my.py %planet% ${bamboo.mynamespace.%planet%}
But doing it like the second example above results in my python script receiving
${bamboo.mynamespace.%planet%}
as a string and not the value of
${bamboo.mynamespace.moon}
I know... moon is not a planet
I don't think it's going to be possible in the way how you're using it. Because once you use ${bamboo.variableName} Bamboo tries to resolve the variable and substitute it with a variable value. Since there's no variable%planet% Bamboo can't reference it.
But I think you could reorganise your solution a bit and make use environment variables (all Bamboo variables are passed to process as environment variables). So e.g. if Bamboo variable's name is variable.name you're allowed to reference to it via ${bamboo_variable_name} (bamboo prefix + all dots are replaced with underscore)
Then I can imagine you could get variable which interests you via print os.environ['bamboo_mynamespace_' + 'planet'] (more info on env variables in python here)
I'm reading this:
You can delete a variable with the command unset varname. Normally this is not useful, since all variables that don't exist are assumed to be null, i.e., equal to empty string "". But if you use the option nounset which causes the shell to indicate an error when it encounters an undefined variable, then you may be interested in unset.
My first question is: I cannot see why the use of unset be not useful; if I want to put my variable to null I can use it (or set variable="" or variable=). On the other hand, if I have a variable that doesn't exist, I don't know why I should have to use it..
My second question is: Why may I be interested in unset in that case?
There is a relevant difference between unset and empty variables.
When you can't tell in front which variables will be used, you can process the output of set (examples: https://stackoverflow.com/a/43419722/3220113 and https://stackoverflow.com/a/28104421/3220113 ).
You might have a situaton where you have sourced a read-only config file, but you do not want all lines set in your environment. In that case you might want to unset the settings you do not need.
When you write some utility that uses some variables, you do not want to leave garbage in the environment. Next to using local variables using unset is another possibility.
I think I have found the answer to my question.
1) If you need to remove the definition and the content of a variable you can use unset command. However, unless you turn on the nounset set option, Korn Shell will allow using variables which don't exist, and it will default the content of such a variable as an empty string. That's why you normally don't use unset: because you normally leave the nounset option off and test variables via conditional logic. Hence in these cases, i.e. the inhibition of the use of a variable, it is not useful. (Obviously, it remains useful for deleting variables - as noted by #Walter A, i.e. "" is not unset, the complete removal of the variable.)
2) That said, it follows that if you use the nounset, unset command makes sense. Indeed, if you unset a variable, the shell will disallow using it.
This is a system Octopus Deploy Variable:
#{Octopus.Action[Deploy To Server].Output.Package.InstallationDirectoryPath}
The text "Deploy to Server" is the name of the step in my project that deploys the Nuget Package to the server. This variable gives the install location of the NugetPackage.
I am wondering if I can make this more generic:
#{Octopus.Action[#{DeploymentStep}].Output.Package.InstallationDirectoryPath}
#{DeploymentStep} is itself a variable with the value of "Deploy to Server"?
I tried this and it not did do the substitution when it tried to run. But I am hoping there is a different syntax for variable in variable substitution.
(I want to do this so I can make this the default value for a Step Template.)
It can be done; but you need to use slightly different syntax!
Variable substitution syntax: http://docs.octopusdeploy.com/display/OD/Variable+Substitution+Syntax
$deploymentStep = "#{DeploymentStep}"
$installationDirectory = $OctopusParameters["Octopus.Action[$deploymentStep].Output.Package.InstallationDirectoryPath"]
Have just had the same issue, but with a few tests I got it working in a 1 liner.
You need to encapsulate the inner variable in brackets with a dollar, and you need to change the double quotes within the variables to single quotes so it doesn't complain about the miss match of quotes. Double quotes on the outside and single quotes in the in.
The example below gets a step name with an octopus variable and also a the machine name it ran on variable to produce the result:
$OctopusParameters["Octopus.Action[$($OctopusParameters['Octopus.Step.Name'])].Output[$($OctopusParameters['Octopus.Machine.Name'])].MyVarFromMachineFromStep"]
I am using a switcher that exports environmental variables based upon which machine is being used. One of the variables that gets exported is ems_1 .
Now, in my start.bash script, I am trying to assign a variable called provider with the value ems_1 has.
export provider = ems_1
Doesn't work . Any suggestions ?
export provider=$ems_1
You need to reference variables using the $ sign.
variable=value
cannot have spaces in-between.