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
bash script dynamically set directorie range
I have the following challenge:
imagine an extensive backlog you need to be able to scan through on request.
directory structure is basically like…

Asgair
- 607
- 5
- 11
1
vote
2 answers
How to expand file content with powershell
I want to do this :
$content = get-content "test.html"
$template = get-content "template.html"
$template | out-file "out.html"
where template.html contains
$content
and test.html…

user310291
- 36,946
- 82
- 271
- 487
1
vote
1 answer
How can zsh array elements be transformed in a single expansion?
Say you have a zsh array like:
a=("x y" "v w")
I want to take the first word of every element, say:
b=()
for e in $a; {
b=($b $e[(w)0])
}
So now I have what I need in b:
$ print ${(qq)b}
'x' 'v'
Is there a way to do this in a single expansion…

Pablo Lalloni
- 2,615
- 19
- 20
1
vote
1 answer
Bash Parameter Expansion - match up to but not including regex
I want to match up to but not including a given string. So in a text like
seirots-llet-ew-yhw-20-30-seirotS lleT eW yhW - yrotS ruoY lleT
I want it to be reduced to
20-30-seirotS lleT eW yhW - yrotS ruoY lleT
So I have a set of reversed strings…

atefth
- 1,624
- 13
- 26
1
vote
2 answers
Can bash substring replacement use regexs?
Given a string such as
string="val1 val2 val3 val4"
how can you use bash substring replacement to remove a given substring and its adjoining space (which may or may not be present)?
For example, this results in extra…

smeep
- 332
- 1
- 17
1
vote
1 answer
bash variable expansion and quoting for part of find command
I have some code like the following inside a Bash script:
FileNames=""
while read -r FileName; do
...
FileNames+=" -o -iname \"$FileName\""
...
done <"$ListOfFileNames"
FileNames="${FileNames# -o }"
find foo -type f \( $FileNames…

knokej
- 71
- 7
1
vote
1 answer
Understanding indirection
I'm currently working on cleaning up some shell scripts. While doing that, I came across something that looks like this:
if [ ${#VARA} -eq 0 ] || [ ${#$VARB} -eq 0 ] || [ ${$VARC} -eq 0 ]; then
...
fi
As you can see, there are three different…

Matthew Herbst
- 29,477
- 23
- 85
- 128
1
vote
0 answers
nested defines in makefile
I'm very new to creating makefiles, so this question might be trivial. If I'm using bad coding practices, I would appreciate to be pointed at it.
I am trying to create a generic makefile that creates rules based on input variables. At the end of my…

weyounsix
- 11
- 3
1
vote
2 answers
AWK - How can I get the values that it equal among them? if ... $1== $1?
I am working with a list of DNA sequences. I would like to get all the sequences with the same name ($1). I was thinking to use if ($1 == "$1"). But this does not work.
result_file:
name1 number1 number2 sequenceofname1
name1 number3 number4…

pickoka
- 35
- 2
1
vote
1 answer
Weird Windows 10 batch compatability issue
I just upgraded Windows 10. But the batch file I wrote not works completely. Same coding was working with Windows 7. That's the piece of code.
:BASLA
SETLOCAL ENABLEDELAYEDEXPANSION
set "s=DIR D:\Diziler /S /Q ^|FIND /i "Administrators" ^|findstr…

Rıdvan Çetin
- 183
- 5
- 16
1
vote
1 answer
Center a Text in terminal
I write the follow script, to print one name to the center of my terminal. In the last command, when i use numbers, everything is ok. However, when i use variables x_center and y_center i have a trouble...
#!/bin/sh
`clear`
num_lines=`tput…

Panagiotis
- 511
- 8
- 26
1
vote
2 answers
Getting "Access denied" with perl dbi when password is read from a file
I am trying to write a simple perl script to pull the full contents of a table from a MySQL database using DBI.
I want to not have to put the database password in the script, so I'd like to set a password variable that reads from a file that…

barret
- 13
- 4
1
vote
1 answer
set default values for bash variables only if they were not previously declared
Here's my current process:
var[product]=messaging_app
var[component]=sms
var[version]=1.0.7
var[yum_location]=$product/$component/$deliverable_name
var[deliverable_name]=$product-$component-$version
# iterate on associative array indices
for…

jjno91
- 653
- 7
- 19
1
vote
3 answers
Expand a bash variable, but not the variables it contains
I need to be able to expand a variable into exactly what is it declaration string is rather than bash expanding other variables in its declaration like it normally does.
variable=word
var="this variable contains a $variable"
echo ????
I need a…

jjno91
- 653
- 7
- 19
1
vote
1 answer
Why does this Bash pathname expansion not take place?
I'm struggling with Bash variable expansion. Please see the following code:
~/tmp 689$ a=~/Library/Application\ *; echo $a
/Users/foo/Library/Application *
~/tmp 690$ echo ~/Library/Application\ *
/Users/foo/Library/Application Scripts…

Chul-Woong Yang
- 1,223
- 10
- 17