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
0 answers
How to correctly expand a file name with spaces as a variable within double quotes in Bash?
Minimal example:
f="/tmp/a file"
cmd="cat \"$f\""
set -x
$cmd
How do I correctly handle $f here such that cmd becomes cat "/tmp/a file" (double or single quote).
cmd="cat '$f'" also doesn't work.

Daanturo
- 124
- 2
- 7
0
votes
0 answers
Prevent variable expansion in Bash heredocument
I would like to create a longer multiline string in Bash without variable expansion. This text contains also items like ${varname} which is expanded according to the specification. However, I don't want to expand them in my script.
Dockerfile=`cat…

FERcsI
- 388
- 1
- 10
0
votes
0 answers
echo-ing a bash variable in curl doesn't work
Okay, so I have tried this:
curl -X 'POST' \
'http://localhost:5000/log' \
-H 'Authorization: Basic $token' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{}'
and there seems to be absolutely no way I can run…

Guillaume Chevalier
- 9,613
- 8
- 51
- 79
0
votes
3 answers
bash command expansion
The following bash command substitution does not work as I thought.
echo $TMUX_$(echo 1)
only prints 1 and I am expecting the value of the variable $TMUX_1.I also tried:
echo ${TMUX_$(echo 1)}
-bash: ${TMUXPWD_$(echo 1)}: bad substitution
Any…

yorua007
- 803
- 3
- 9
- 14
0
votes
0 answers
Delayed Expansion causing my script window to close but not fail
I have a set of variables that represent directory names: folder_1, folder_2,... folder_n.
In my code I am trying to set the variable FOLDER to the correct directory name based on the user input selection after validating the value with a…

HotSteel
- 11
- 6
0
votes
1 answer
how to disable variable expansion when using bash "eval"
hi I have following propertie file (something.properties)
SERVER1_PROPERTY1=123
SERVER1_PROPERTY2=${SERVER1_PROPERTY1}/123
and following bash script fetching one of the properties:
#!/bin/bash
. something.properties
SRV="SERVER1"
eval…

user892960
- 309
- 2
- 11
0
votes
1 answer
challenge with bash variable expansion
I am creating a script called "convert_mkv_mp4_v3.sh"
#!/bin/bash
# If no directory is given, work in local dir
if [ "$1" = "" ]; then
DIR=.
else
DIR="$1"
fi
arrayname=()
while IFS= read -d '' -r filename; do
arrayname+=("$filename")
done <…

rnng
- 1
0
votes
1 answer
How to excape special syntax characters in string variable in bash
GIVEN:
A string variable containing characters that are used by bash for expansion or as delimiters, e.g.
> path="/this/path/contains whitespace/and/asterisk */myfile.txt"
GOAL:
I want to expand the variable in a way that those bash syntax elements…

Frank-Rene Schäfer
- 3,182
- 27
- 51
0
votes
0 answers
variable expansion not happening when importing to Makefile
I have a shell script with some variables w/ variable expansions:
$ cat version
#!/bin/bash
export GIT_TAG=`git describe --tags --always --dirty`
export BUILD_NUM=${TRAVIS_BUILD_NUMBER:-${GIT_TAG}}
export VERSION="0.1.${BUILD_NUM}"
Then I'm trying…

jersey bean
- 3,321
- 4
- 28
- 43
0
votes
1 answer
variable expansion in echo and terminal
Bash version:
debian@debian:~$ bash --version |grep release
GNU bash, version 5.1.4(1)-release (x86_64-pc-linux-gnu)
Variable expansion in echo:
debian@debian:~$ a=apple
debian@debian:~$ echo '"'$a'
'
"apple
debian@debian:~$
I type '"'$a' and…

showkey
- 482
- 42
- 140
- 295
0
votes
1 answer
Chopping suffixes in variable expansion within a Makefile
As the title states, I have a problem being able to remove suffix from a package name if I need to provide several suffixes (pattern-list)
Note: I have forced bash usage in the Makefile (SHELL=/bin/bash)
DEST_DIR: Makefile variable
PKG_LIST:…

AirconBento
- 3
- 3
0
votes
1 answer
Trouble with Azure API Management TRACE policy rule not expanding variables in the message
Following the instructions from this page https://learn.microsoft.com/en-us/azure/api-management/api-management-policy-expressions and this page https://learn.microsoft.com/en-us/azure/api-management/api-management-advanced-policies#Trace , I am…

djangofan
- 28,471
- 61
- 196
- 289
0
votes
0 answers
variable not expanding in cURL option
Can's seem to get a variable to expand within a cURL option.
I've tried various approaches including the following:
curl -X POST http://localhost:9047/api/v3/sql \
-H 'Authorization: ${mytoken} ' \
curl -X POST http://localhost:9047/api/v3/sql \
-H…

Lew Goldstein
- 61
- 4
0
votes
1 answer
Variable not expanding in zsh printf
I'm trying to execute the following printf statement in a zsh script I'm working on:
printf "%s\n" "${CREATE_WS[@]}"
Where $CREATE_WS is an indexed array as…

Karie Adair
- 1
- 1
0
votes
1 answer
Doyxgen onetime macro expansion / expansion command
I have some code like the following example:
/** @file HelloPi.c */
/** The definition of pi */
#define PI 3.1415
/** @brief The main function.
* @details Prints the value of #PI, which is actual defined as 3.1415. */
void main()
{
printf("The…

Jan
- 7
- 2