Skip to main content

Questions tagged [variable-substitution]

Use where the name of a variable is textually substituted with the value of the variable

6votes
4answers
586views

Using curly braces to process colon-separated variables

If we do: VAR=100:200:300:400 We can do: echo ${VAR%%:*} 100 and echo ${VAR##*:} 400 Are there any equivalents I could use to get the values of 200 and 300? For instance, a way to get only what's ...
Cestarian's user avatar
0votes
0answers
20views

Shell expension in variable allocation containing the char '*' [duplicate]

For the shell fans (bash) : I want a variable to get a value resulting from an operation output which contains an globbing character (such as *), and the shell expansion always happens, even if I ...
misterpc's user avatar
0votes
1answer
49views

Variable substituion ":+" in automake

On ubuntu 24.04 GNU bash, version 5.2.21(1)-release (x86_64-pc-linux-gnu) automake (GNU automake) 1.16.5 autoconf (GNU Autoconf) 2.71 From automake doc ${var:+value} Old BSD shells, including the ...
maths soso's user avatar
0votes
2answers
84views

zsh: substitute-if-undef-or-null for $1, $2 …: ${1:substitution} doesn't work

I'd like to have standard parameters, i.e., my minimum reproducible example is: #!/usr/bin/zsh a=${1:a} printf 'a: "%s"\n' "${a}" b=${2:./build} printf 'b: "%s"\n' "$...
Marcus Müller's user avatar
1vote
1answer
46views

How To Use Quotes In Variable In Bash [duplicate]

I need to assign a command to a variable and execute it with variable in linux bash. The command executes fine from command line but not from the variable because of multiple quotes. I hope backslash ...
Kishan's user avatar
1vote
6answers
232views

Move a lot of folders with spaces in the name

I have a lot of webpages saved in my Download folder and I want to move all html files together with its folder (for every "NAME.html" exists "NAME_files/" folder). The big ...
Antonio's user avatar
0votes
4answers
172views

bash - slice quoted substrings delimited by spaces into array

following example: string=" 'f o o' 'f oo' 'fo o' " array=($string) echo "${array[0]}" outputs: 'f while the expected output is: 'f o o' The only solution I came with is by ...
Zero's user avatar
0votes
1answer
95views

Is there a tool that can print out a bash script with the variables substituted? [duplicate]

Say I have a bash script that takes some environment variables and parameters and substitutes those variables in a script. Is there a tool that can show how the script with the substituted variables ...
vfclists's user avatar
2votes
2answers
273views

Zsh Expanding Variables into Arrays or Lists

I looked through some of the posted threads and none of them cover my query. I have a simple line of code below which prints all the ASCII characters: echo {' '..'~'} I want to be able to use a ...
James Bond's user avatar
0votes
0answers
24views

Bash variable losing value [duplicate]

I recently added a variable to a script process that will be used as a replacement value via sed for an output script (not bash). This is one of many variables set within an if statement and (for ...
Raymond Meyer's user avatar
0votes
1answer
40views

Does Bash have an option to diagnose "expanded to empty value" variables? [duplicate]

Does Bash have an option to diagnose (and optionally abort execution) "expanded to empty value" variables? Example (hypothetical): $ bash -c 'echo $x' --xxx bash: line 1: variable 'x' ...
pmor's user avatar
  • 593
0votes
1answer
66views

Bash nested variable [duplicate]

I source these variables from a txt file in CentOS bash shell: NAME01=dns1 HOST01=1.1.1.1 NAME02=dns2 HOST02=1.1.2.2 NAME03=dns3 HOST03=1.1.2.3 ## many more lines of similar NUM=02 How can I use $...
SmplJohn's user avatar
0votes
0answers
19views

bash variable problem [duplicate]

Apologies if this is nooby question but I am new to bash scripting and I couldn't find anything similar. I am trying to use ffmpeg to re-encode a load of files and that requires I pull out some ...
Andy Ashwood's user avatar
7votes
1answer
1kviews

printf - store formatted string output in a variable

Instead of the following printf '%s\t%s\t%s\t%s\n' 'index' 'podcast' 'website' 'YouTube' I want to store the printf output in a Results variable, how can I do this?
Porcupine's user avatar
-1votes
1answer
65views

Output of loop variable shows different value than expected

Imagine I have two folders in my current working directory: back/ and front/. I am trying to enter inside each of them and do some stuff. From the simple script below: for dir in */ ; do echo &...
Rigel F. do C.'s user avatar

153050per page
close