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
0 answers
Using Bash parameter expansion with Required check
I am trying to strip the string value in the variable and copy to another variable using bash parameter expansion.
initialModified=${initial#abc}
This give me the value in initialModified after stripping out abc from the beginning of the string in…

dreddy
- 463
- 1
- 7
- 21
1
vote
1 answer
String items in Variable / Parameter Expansion
I'm trying to use a variable instead of explicitly listing my zone list in multiple places.
I realize that I could just download all of the files, and just apply the ones I'm looking for. I feel like I should be able to do this, and I guess this…

Jason Justinger
- 13
- 5
1
vote
4 answers
Parameter expansion not working when used inside Awk on one of the column entries
System: Linux. Bash 4.
I have the following file, which will be read into a script as a variable:
/path/sample_A.bam A 1
/path/sample_B.bam B 1
/path/sample_C1.bam C 1
/path/sample_C2.bam C 2
I want to append "_string" at the end of the filename…

msimmer92
- 397
- 3
- 16
1
vote
1 answer
How to Create Text Files from an Array of Values in Powershell
I have a text file "list.txt" with a list of hundreds of URL's that I want to parse, along with some common-to-all config data, into individual xml files (config files) using each value in "list.txt", like so:
list.txt…

Scott Coats
- 75
- 8
1
vote
2 answers
How do I use a variable in Postgres scripts?
I'm working on a prototype that uses Postgres as its backend. I don't do a lot of SQL, so I'm feeling my way through it. I made a .pgsql file I run with psql that executes each of many files that set up my database, and I use a variable to define…

OwenP
- 24,950
- 13
- 65
- 102
1
vote
1 answer
Variable expression %Var% not working in for loop in batch file
FOR /F "tokens=* USEBACKQ" %F IN (java -jar %MAVEN_HOME%\jenkins-cli.jar -s http://someip.com build /dev/ -s --username **** --password ***) DO (SET var=%F)
Here %MAVEN_HOME% value is not getting replaced with the actual value but when I run this…

arjun kumar
- 467
- 5
- 12
1
vote
1 answer
How to search for martial matches when mysql query contains a placeholder in python?
Query 1:
"SELECT name FROM mytable WHERE name LIKE '%e%'";
This query will look for all names that contain the letter ‘e’.
Query 2:
"SELECT name FROM mytable WHERE name LIKE '%s'" % search_name;
This query will look for all names that contain match…

Evan
- 288
- 1
- 10
- 19
1
vote
2 answers
Why are parentheses (or braces) needed in this minimal Makefile?
I am baffled why I need to echo $(VAR1) or ${VAR1} to get the output "abcd" in this Makefile:
VAR1=abcd
myTarget:
@echo $VAR1
all: myTarget
.PHONY: all
Instead, make will echo $V (which is the empty string), and then "AR1", which is my…

lissachen
- 229
- 1
- 2
- 4
1
vote
0 answers
Nested for in batch executed twice
I have the following code in my batch script:
for %%m in (a b c) do (
cd %%m
dir
for %%f in (*.zip) do rename "%%f" "%%m_%%f"
dir
cd ..
)
It is supposed to prepend the name of the folder a file lives in to the filename. I do so…

Felix
- 6,885
- 1
- 29
- 54
1
vote
1 answer
bash variable substitution not working on Solaris
I have this code snippet running on several Linux boxes, and a Solaris 10 box with bash 3.6 (iirc). However, on a Solaris 11 box, with GNU bash, version 4.4.11(1)-release (sparc-sun-solaris2.11) it gives the following error.
#!/bin/env…

SaintHax
- 1,875
- 11
- 16
1
vote
1 answer
Expanding bash variable within a string
I am trying to get a variable within a string to expand - its a path:
/path/to/${variable}/here
The string originates in a json file.
It is subsequently read by jq - at this point I need the expansion to occur.
Here is the json file:
{
…

JRD
- 83
- 2
- 7
1
vote
2 answers
Shell variables expansion in text file preserving whitespace (e.g. docker-compose.yml usage in Rancher)
I'd like to perform shell expansion with default values in YAML file preserving its structure and leading whitespace, so to keep it usable.
For example:
version: 2
services:
postgres:
image:…

Eugene Lisitsky
- 12,113
- 5
- 38
- 59
1
vote
1 answer
Bash variable sequence expansion (letter range)
Given a couple variables I'd like to concatenate:
# valid
COUNTRIES_A="ad,af,ai,ag,al,am,ao,ar,ax,az,"
COUNTRIES_B="ba,bd,bf,bh,bi,bj,bn,br,bt,bw"
COUNTRIES="${COUNTRIES_A},${COUNTRIES_B}"
is there a sequence expansion that can achieve this a bit…

Mark
- 610
- 9
- 22
1
vote
2 answers
Make zsh aliases work with a prefixed command
Some commands manipulate the environment in some way and then call another command. For example, xargs takes arguments via standard input and appends them to the end of the args list, then runs with those…

Kevin Burke
- 61,194
- 76
- 188
- 305
1
vote
1 answer
String replace *./*: with nothing, using variable passed to batch file from command line
I am ripping my hair out. Why can't there be a debugger made available for batch scripting?
First step of my current batch script (and it does have to be in this "language", as I don't have c/wscript able to be used) is simply to remove the hour…

user66001
- 774
- 1
- 13
- 36