Skip to main content

Questions tagged [variable-substitution]

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

0 votes
0 answers
43 views

I have a little maintenance thing to do as super user, from time to time. I would like that to be a one-liner, for easy copying from my self-documentation to a terminal. I reduced it to the bare ...
db-inf's user avatar
  • 333
12 votes
2 answers
1k views

I was debugging one script, and discovered unexpected behavour of handling arithmetic syntax error. Normally, when error happens, script is just continuing execution. #!/bin/bash func2 () { echo &...
Ashark's user avatar
  • 1,219
4 votes
2 answers
364 views

I have a command that takes always the same initial parameters. I can create a variable to capture these parameters. Also, I need to pass the output of a subshell running the same command to the ...
k314159's user avatar
  • 533
2 votes
1 answer
388 views

All we get in Makefiles is just one %/$* pattern rule pair. $ cat Makefile %.bla:; echo $* $ make -s m.bla m How shortsighted of our Unix™ fathers. How can I achieve something like %{0}.%{1}.bla that ...
Dan Jacobson's user avatar
0 votes
0 answers
49 views

For a school project, I am tasked with making my own (simplified) shell, with bash being the reference point. This includes replicating heredoc behavior which was fun until I stumbled upon variable ...
Mika's user avatar
  • 101
6 votes
4 answers
993 views

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
  • 2,593
0 votes
0 answers
21 views

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
0 votes
1 answer
83 views

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
0 votes
2 answers
162 views

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
1 vote
1 answer
69 views

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
  • 113
1 vote
6 answers
404 views

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
  • 203
0 votes
4 answers
309 views

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
  • 71
0 votes
1 answer
157 views

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
  • 7,919
2 votes
2 answers
551 views

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
0 votes
1 answer
74 views

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
  • 757

15 30 50 per page
1
2 3 4 5
23