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
0
votes
3 answers
Expand variables as part of a command in bash
Is there any way to expand variables inside commands?
It's hard for me to explain what I want to achieve, so I'll demonstrate it:
Let's say I have this construct:
var1="\${var2} -eq 7"
if [ ${var1} ]; do....
And the desired output is:
if [ ${var2}…

Lhakryma DL
- 59
- 7
0
votes
0 answers
Text expansion in Cmder / ConEMU
A long time ago, I set my Cmder (ConEMU) to expand "~" to C:\Users\%USERNAME%.
Embarrassingly, I have forgotten how I did it.
Now I'd like to un-do it.
I've checked my alias files and ran "Multifind" searches in the /Cmder directory, but have not…

TecBrat
- 3,643
- 3
- 28
- 45
0
votes
2 answers
Early Expansion of Variables in Recipes
I know about the distinction between the two kinds of variables in GNU Make.
I am currently writing a build system where certain variables are defined in sub directories (e.g., VERSION). To make the life simpler for authors of subdirectories, I do…

choeger
- 3,562
- 20
- 33
0
votes
1 answer
How to avoid breaking a string parameter into multiple parameter?
I want to pass a string parameter to a Bash procedure. This procedure prints the string on console and prints a copy to a file.
In my use case, this file will contain a list of all executed commands in a Bash script that can be used to rerun all…

Paebbels
- 15,573
- 13
- 70
- 139
0
votes
1 answer
Bash Expansion Mystery
This is a very "popular" topic on stackoverflow and unfortunately I haven't been able to figure this out when looking at other questions. Anyways let's consider the following scenario.
A function gets a bunch of string arguments like…

MarkoPaulo
- 474
- 4
- 19
0
votes
1 answer
How to pass a variable args="foo bar=\"baz qux\"" as exactly *2* arguments?
Take the following script:
#!/bin/bash
function print_args() {
arg_index=1
while [ $# -gt 0 ]; do
echo "$arg_index: $1"
arg_index=$(expr $arg_index + 1)
shift
done
echo
}
echo "print_args foo bar=\"baz…

Jon McClung
- 1,619
- 20
- 28
0
votes
0 answers
bash parameter expansion whitespace
Is there a way to evaluate any string variable, when the string/variable name has been defined inside a script? Answer: Yes. See below. Note how it handles various kinds of whitespace.
#!/bin/bash
function infunction () {
printf '%s\n' '--- next…

Jacob Wegelin
- 1,304
- 11
- 16
0
votes
0 answers
How to escape bash parameter expansion (when a "!" followed by letters is a parameter)
I have a bash script I need to call with a string parameter, which string starts with a exclamation mark "!" (this is mandatory in what I'm doing):
myCommand.sh "!HELLO"
Because of parameter expansion, bash reports an error:
-bash: !HELLO: event…

Bob
- 1,495
- 1
- 19
- 24
0
votes
2 answers
What is the difference between ${@:2} and ${*:2} in these cases?
Given the following code in bash:
filename=${1}
content1=${@:2}
content2="${@:2}"
content3=${*:2}
content4="${*:2}"
echo "${content1}" > "${filename}"
echo "${content2}" >> "${filename}"
echo "${content3}" >> "${filename}"
echo …

AskMath
- 415
- 1
- 4
- 11
0
votes
2 answers
Surpressing shell expansion when truncating variable obtained by asterisk
In my folder I have following…

micholeodon
- 85
- 7
0
votes
0 answers
Dynamic variable name in cmd.exe w/ command extensions
I see this is a common theme, but I believe I have a unique problem.
I want to use this technique of variable expansion, where you can use the ":" to substitute strings in expanded result (the "&" part being a trick to force command execution)
echo…

Ate Somebits
- 287
- 1
- 18
0
votes
1 answer
Understand flag setting
I am trying to install BerkeleyDB STL .
I ran the following code to download n install the same
curl -OL http://download.oracle.com/berkeley-db/db-6.2.23.NC.tar.gz
tar xf db-6.2.23.NC.tar.gz
cd db-6.2.23.NC/build_unix
../dist/configure…

fireball.1
- 1,413
- 2
- 17
- 42
0
votes
1 answer
Bash: var expansion confusion possibly due to IFS
After reading about getting files with spaces in the name using find, I put together a small code chunk to grab all .sh files in a directory and make them executable:
find . -type f -name '*.sh' -print0 |
while IFS= read -r -d '' file; do
…

bleachbyte
- 3
- 1
- 3
0
votes
1 answer
Batch script with nested expansions not working
I'm trying to set a variable with the result of a nested variable expansion. month is an array of month names, from January (01) to December (12). monthNow holds the current month's code (e.g., 01). Here is my code:
@echo off
setlocal…

midoriha_senpai
- 177
- 1
- 16
0
votes
1 answer
Common Lisp macro variable expansion
(defmacro foo (x)
`(defun ,xt ()
(format t "hullo")))
(foo bar)
will not define a function bart, since ,xt is read as the variable xt rather than the variable x plus a t. But is there a way to get a function bart by supplying the…

Toothrot
- 334
- 2
- 10