This question already has answers here:
Sass Variable in CSS calc() function
(6 answers)
Closed 2 years ago.
This code doesn't work is Sass:
$color1:
.App {
--color1: $color1;
}
Why is this not valid syntax? What is the proper syntax?
This being invalid syntax is intended, the solution is to use:
$color1:
.App {
--color1: #{$color1};
}
The reason for this is discussed here: https://github.com/sass/libsass/issues/2621
In short, css variables could potentially be a string that starts with a $ character, and Sass did not want to block that syntax from working. Given that #{$someVar} is not valid css syntax, it is functional and more explicit to have it be this way.
Related
This question already has answers here:
Dynamic variable names in Bash
(19 answers)
Closed 8 months ago.
I'm working in a GitLab runner environment and CICD Variables with two familiar strings in my bash script and I would change one of these strings in the middle to build a final string. For example:
$CICD_MY_INTERNAL_STRING
$CICD_MY_EXTERNAL_STRING
So now these strings are in my function "workerapp()" and I would make this string dynamic.
function workerapp() {
echo -e $CICD_MY_$1_STRING
}
Now I would call the function like this
workerapp INTERNAL
workerapp EXTERNAL
to get these results
"$CICD_MY_INTERNAL_STRING" and "$CICD_MY_EXTERNAL_STRING" to work with it in another functions / calls.
Currently I got only these results "$CICD_MY_EXTERNAL" ... without the rest of my strings.
You could use the ${!varname} construct.
workerapp() {
local varname="CICD_MY_$1_STRING"
echo -e "${!varname}"
}
workerapp INTERNAL
workerapp EXTERNAL
This question already has answers here:
Bash - variable variables [duplicate]
(4 answers)
Dynamic variable names in Bash
(19 answers)
Closed 4 years ago.
Suppose I have several variable names like
V_1_T = a
V_2_T = b
V_3_T = c
...
and I want to extract the pointers a, b , c, ... in a bash loop in order to concatenate the values. My explicit wish is about reconstructing a message separated in several parts as explained in the gammu-smsd documentation.
I've tried the example in the doc but it doesn't work. The reason is that the code never points to the pointer of the variables but to the variables themselves, i.e. I get V_1_T at best and never a as I would.
I've also tried to put
${V_${i}_T} ; ""$"V_${i}_T"
with and without escape symbols for the commas, ..., but nothing worked ...
Any ideas ?
I'm working on the latest version of Raspbian + RaspberryPi.
Use indirect parameter expansion:
for i in 1 2 3; do
t="V_${i}_t"
echo "${!t}"
done
This avoids the use of eval shown in the docs you linked to.
This question already has answers here:
When do we need curly braces around shell variables?
(7 answers)
Closed 6 years ago.
In Pycharm when we use variable e.g. $privateKey, we get the warning Simple variable usage as below snapshot and recommend us to turn to the syntax ${privateKey}
My question is why we get such warning? What is the risk to use simple variable like that?
When clicking more
Thanks to #Whymarrh. One answer is as below.
since "$foobar" would instead expand foobar
My answer is to separate/distinguish $myVar and notInVar in string "$myVarnotInVar"
In other words
myVar=122
echo "$myVarnotInVar" # will print empty string "" since undefined variable $myVarnotInVar
echo "${myVar}notInVar" # will print 122notInVar
This question already has an answer here:
What is the Ruby equivalent of preg_quote()?
(1 answer)
Closed 7 years ago.
Lets say I want to match against CVS comments like:
// $Source$
My regex currently looks like this:
if ( /^\/\/\s*\$Source\$/ =~ line)
Which works, but I'm left wondering -- is there a prettier way to write this?
Use the %r syntax:
if ( %r{//\s*\$Source\$} =~ line)
^^ I'm not sure whether ruby would allow unescaped `$` here or not
This question already has answers here:
How do you do block comments in YAML?
(11 answers)
Closed 6 years ago.
I know that you can make a single line comment in YAML by using the # tag, but I haven't been able to find something like /* in java that starts a comment & has to be finished off with a */. Does such an operator exist in YAML?
YAML does not support multiple line comments. If you want to use them. You can just try
# this
# is a multiple
# line comment