Evaluating or expanding a variable to get its value. Depending on the language, a variable may be expanded one or more times.
Questions tagged [variable-expansion]
246 questions
1
vote
1 answer
Variable expansion in Makefiles
Make seems to be expanding variables only after a rule is active.
make ok displays the resolved NAME (ie. "test")
make bad claims to depend on "grep" (rather than "test")
How can I get make to expand NAME before it checks the dependencies of the…

BlueChip
- 143
- 2
- 13
1
vote
2 answers
Expanding var names of __VA_ARGS__ in C++ preprocessor macro
I'm trying to implement a proper enum to str macro which would automatise the association between enum values and their name in the code.
For example I'd like to define a new macro called "Test" like this:
ENUM_STR_DECLARE(Test, 1, test1, test2,…

nadrino
- 103
- 6
1
vote
1 answer
How to pass multiple arguments including arrays to a function in Bash where order is not defined and array elements can have multiple words?
I'm for hours trying to figure this one out.
What I would like to do is have a function that can receive N parameters which can include arrays.
Arrays can be in any parameter position, not only the last!
Order of parameters can change, for example,…

user5507535
- 1,580
- 1
- 18
- 39
1
vote
1 answer
ExpandString breaks EOL
Context
I have a multi line file named DEV.properties. It contains references to ENV variables
ACTIVEMQ_DB_USERNAME=${ACTIVEMQ_DB_USERNAME}
I am writing a ps script to replace this file with one populated with the relevant variables
Problem
Here is…

zar3bski
- 2,773
- 7
- 25
- 58
1
vote
0 answers
get literal value of bash variable, without glob expansions or other changes
I have a folder with some xml files in it: 1.xml, 2.xml and so on.
Then i am doing:
a=*.xml
echo $a
I am getting list of these xml files like this:
1.xml 2.xml
But then i am doing
a=*.qwe
echo $a
I am getting literal value of a:
*.qwe
Then I am…

ilya
- 119
- 1
- 13
1
vote
1 answer
PowerShell string format different behaviour within function
While using powershell I struggle to build up a filename from two variables. When I originally creaded the powershell script, it was working fine. Now I have tried to move some repeatable steps into a function, but the string behaviour is…

Crumar
- 122
- 10
1
vote
0 answers
batch file setlocal confusion
I am having difficulty understanding how batch file localization works. Here is an example to demonstrate my confusion
@echo off
set x=5
set y=1
setlocal enabledelayedexpansion
if %y% GEQ 1 (
set x=6
echo %x%
echo !x!
)
echo…

danny
- 1,101
- 1
- 12
- 34
1
vote
2 answers
Can a variable expansion in python work like shell expansion of variable
I have a legacy python code that reads from a shell script for variable values like in a properties file. For example, say, I have a shell program x.sh for variable declaration…

Dr. Debasish Jana
- 6,980
- 4
- 30
- 69
1
vote
0 answers
Bash 4.4 fails autocomplete environment variable for "more" but not "less" or "cd"
I am working on a server that runs Ubuntu 18 and bash 4.4, and I have problem with autocompletion and expanding paths stored in environment variable, but only if I use the "more" command:
$ echo $TEST_DIR
$ export…

Yehudit Hasin
- 21
- 3
1
vote
4 answers
Bash variable expansion
I have a string made up of directories with a space after each one
dirs="/home /home/a /home/b /home/a/b/c"
the following code deletes the last directory in the string.
dirs=${dirs% * }
This works in all cases except when only one directory is…

DanielST
- 13,783
- 7
- 42
- 65
1
vote
1 answer
$(file < $@) expands to nothing but it should not
I wrote this make rule
$(COMPDIR)/%.d: $(COMPDIR)/%.cpp
# other code...
$(file > $@,$(foreach path,$(file < $@),$(shell echo "$(path)" | sed 's!$(SRCDIR)/!$(COMPDIR)/!')))
# other code...
This should read the target file $@, tokenize its…

qub1750ul
- 88
- 1
- 7
1
vote
3 answers
Bash - Expanding a variable into another variable name
Let's say I have these variables:
VAR_A=resultA
VAR_B=resultB
X=A
I want to get the value of VAR_A or VAR_B based on the value of X.
This is working and gives resultA:
VAR="VAR_$X"
RESULT=${!VAR}
My question is, is there a one-liner for this?…

scandel
- 1,692
- 3
- 20
- 39
1
vote
0 answers
how to expand expression string in powershell
is there any comlet like expand-string?
$a="ab cd"
$command = 'dir $a'
Write-Host (expand-string $command)
expected:
dir abcd
Note, I know I can just use $command="dir $a" to expand the string, but that was not I want to, I need to save the string…

xinglong
- 115
- 1
- 5
1
vote
1 answer
Write a user supplied command to file
I need to write a user supplied command to a file with bash.
Testcase would be script.sh -- echo "Hello \$USER" and I want a file containing echo "Hello $USER" (or echo Hello\ $USER) which can be executed
I'm using heredoc to write to the file, so…

Flamefire
- 5,313
- 3
- 35
- 70
1
vote
1 answer
Wrong expansion of variable in Makefile.am
I am stuck with a strange variable expansion. Let me explain.
I have a project that uses automake, composed by configure.ac, Makefile.am.
Basically, in Makefile.am I'm doing:
ARCH = $(shell ${CURDIR}/./arch.sh)
...
noinst_HEADERS =…

Kyrol
- 3,475
- 7
- 34
- 46