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
2
votes
1 answer
Why does GNU Make re-run my shell command every time it expands this variable?
I use OpenSSL to generate some random data in a GNU Makefile:
RANDOM_DATA=$(shell /usr/bin/openssl rand -hex 32)
I want to be able to use this RANDOM_DATA multiple times elsewhere in the script. However, every time it's referenced, it re-runs the…

Steve
- 6,334
- 4
- 39
- 67
2
votes
1 answer
Zsh does not expand path in `--flag=path` style arguments
In bash:
$ foo --bar=/tmp/ba
expands to foo --bar/tmp/baz. In my zsh install, no expansion is performed here (but is performed as expected when the path is separated by whitespace, i.e. foo --bar /tmp/ba). What zsh setting do I need to…

Sasgorilla
- 2,403
- 2
- 29
- 56
2
votes
2 answers
Bash array variable expansion inside expect command
An extension to this question :
Bash : Adding extra single quotes to strings with spaces
After storing the arguments of command as a bash array
touch "some file.txt"
file="some file.txt"
# Create an array with two elements; the second element…

anoop.babu
- 405
- 2
- 6
- 13
2
votes
2 answers
Can Java Streams transform a list of points into a list of their coordinates?
I have a stream of Point3Ds in a JavaFX 8 program. I would like, for the sake of creating a Mesh from them, to be able to produce a list of their (x, y, z) coordinates instead.
This is a simple enough task through traditional Java looping. (Almost…

Michael Macha
- 1,729
- 1
- 16
- 25
2
votes
0 answers
GNU Make: How to perform second expansion with suffix-changing substitution
What I'm going for (what's failing)
I have a list of dependencies for each file:
point_deps =
bounds_deps = point
triangle_deps = point bounds
Image_deps = types bounds triangle
main_deps = Image triangle bounds point types
I'd like to write a rule…

joshterrell805
- 1,407
- 2
- 11
- 13
2
votes
1 answer
What does the POSIX spec mean when it says this is necessary to avoid ambiguity?
When responding to this comment:
Now I got the the two ":"s are independent, and that's why I couldn't find any document about them. Is the first one needed in this case?
I noticed this paragraph in the spec for the first time:
In the parameter…

Etan Reisner
- 77,877
- 8
- 106
- 148
2
votes
2 answers
removing a case clause: bash expansion in sed regexp: X='a\.b' ; Y=';;' sed -n '/${X}/,/${Y}/d'
I'm trying to remove a case clause from a bash script. The clause will vary, but will always have backslashes as part of the case-match string.
I was trying sed but could use awk or a perl one-liner within the bash script.
The target of the edit is…

ChrisSM
- 90
- 5
2
votes
1 answer
Shell splitting in subshell
I have unclear information about word splitting in Shell and subshells.
Example:
IFS=""
file_name="file with space"
file_name=$(real_path $file_name)
Will $file_name get split in subshell? Or do I have to double-quote it like…

semtexzv
- 129
- 2
- 10
2
votes
1 answer
shell :How to use UDV in this Grep structure without having issues?
I have an assigment that asks me to print on screen the number of words that are longer than a given number ,let's say k , which is read from the keyboard. and then to order the result.
Until now I decided to try in this way :
#!bin/bash
k=0
if […

Wiuwi
- 23
- 3
2
votes
1 answer
zsh redirection, together with parameter expansion
I'm writing a shell script S which calls a program P.
P accepts its input from stdin only.
One of the parameters of my script S is optional; if the parameter is present, it denotes a file, which should be fed into P. If the parameter is missing,…

user1934428
- 19,864
- 7
- 42
- 87
2
votes
3 answers
Either getting original return value from xargs or simulate xargs
I am working with bash. I have a file F containing the command-line arguments for a Java program, and I need to store both outputs of the Java programs, i.e., output on standard output and the exit value. Storing the standard output works via
cat F…

Oliver Kullmann
- 253
- 1
- 7
2
votes
2 answers
Using quotes with "${parameter:-word}" Parameter Expansion
When using the ${parameter:-word} form of parameter expansion to evaluate to a default value if the variable is unset, what is the best practice for quotes?
For example, assume a Bash shell script with -u set (to generate an error when an undefined…

jetset
- 388
- 4
- 14
2
votes
1 answer
Bash - Command and variable expansion
After reading the POSIX Shell manual and the Bash manual I still can't explain the following behavior:
% bash --version
GNU bash, version 3.2.48(1)-release (x86_64-unknown-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.
% bash
% A=1…

A. Lefebvre
- 139
- 4
2
votes
3 answers
Replace variables in text: Suggestions?
I'm looking for a nice template engine or short piece of code to expand Ant-like variables in a string in Java. Example:
String result = expand ("${firstName} ${familyName}", map);
It should at least support java.util.Map but something that can…

Aaron Digulla
- 321,842
- 108
- 597
- 820
2
votes
1 answer
How does ipython variable expansion works?
I don't understand what the ${} is doing in the fourth and sixth prompt, and I can't find any documentation about this, The book Python for Unix and Linux System Administrator has an example like the one in the sixth prompt, in which the variable is…

HarmonicaMuse
- 7,633
- 37
- 52