All Questions
Tagged with variable-substitution variable
54 questions
1
vote
1
answer
46
views
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 ...
2
votes
2
answers
269
views
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 ...
0
votes
1
answer
40
views
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' ...
7
votes
1
answer
1k
views
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?
0
votes
2
answers
172
views
how to replace a string with a variable?
I am trying to write a script containing a loop that enters a series of directories containing the same file, to replace a text string in a file with a variable that matches the directory's name.
The ...
5
votes
2
answers
478
views
Issue expanding variable with multiple wildcards in bash shell script with mv / rename
I wrote a bash shell script for Linux to move files in a static folder according to parameters specified in a data file.
I've reduced that script to a minimal reproducible example to demonstrate an ...
0
votes
2
answers
392
views
How to grep for the value of a variable inside a shell script?
I have 2 files:
a file full of values I want to look for
my source text file
I wrote a short shell command to loop thru my list of values and grep against my source file. If it doesn't find the ...
0
votes
3
answers
107
views
How to expand variable inside single or double qoutes
I have 2 systems and they have the same directory strcuture. I want to execute a couple of commands on local system and the same on remote system.
I use the wildcards so when I have a new version of ...
0
votes
1
answer
26
views
Error in defining Variables
I am trying to follow this to replace a multiline text.
But to do that I want to put some text like below into a variable.
```dataview
TABLE WITHOUT ID page-no as no, link(file.name, topic) as name ...
1
vote
3
answers
1k
views
What does echo $$ do? [duplicate]
I was messing around with echo and was trying stuff like echo ~. When I was trying to use $ to substitute environment variables I accidentally tried echo $$. Surprisingly instead of an empty line I ...
0
votes
0
answers
136
views
How can I use an already defined variable reference in definition of another variable in shell script/ [duplicate]
I am trying to do something like below :
export a="ABC" # Works fine
export b_"$a"="DEF" # Works fine
Now how do I print or echo the new variable "b_$a" ??
I ...
0
votes
2
answers
1k
views
Export a value from input variable
I need to export the values from input. However it's failing in bash.
Here's the code -
echo "Please enter HOST :"
read RDSHOST && export RDSHOST
And my value is something like - ...
0
votes
0
answers
19
views
Something in the file is messing with ZSH [duplicate]
I have a file with such lines:
map_Kn Ellie_Caruncle_N.png
I'm trying to extract field #2, and use it twice in a command like this, but it's giving me some problems.
Here is a ZSH session:
~/Downloads/...
0
votes
0
answers
503
views
how to expand a variable with backslash in bash script [duplicate]
i read a line from another file that contains a backslash, and i want to echo this line without expanding the backslash :
script.sh :
#!/bin/bash
while read line
do
echo "$line"
done &...
2
votes
2
answers
1k
views
awk evaluate variable in statement
I am new to awk, I tried numerous suggestion found online, but I cannot resolve my problem.
I need variable $number to get evaluated inside the -F arg value.
This statement works as expected:
inn=$(ip ...