All Questions
Tagged with quoting variable-substitution
24
questions
26
votes
6
answers
125k
views
Is there any way to print value inside variable inside single quote?
Consider I've set variable site and needs to be printed by echo or printf, but If I use single quote to write something and want to use variable then how?
Example:
$ site=unix.stackexchange.com
$ ...
3
votes
1
answer
7k
views
Grep pattern that has double quotes and variable substitution surrounded by single quotes
So, Let's say I have the following pattern:
Thisisatest="1"
in a file called file.
And I want to match the exact string above but for whatever reason, I choose to loop over some numbers ...
8
votes
3
answers
3k
views
How does Bash handle quoting in the string replacement section of parameter expansion?
Is there any consistent logic to it?
some-command "${somevariable//some pattern/'how does this get parsed?'}"
I've posted some conclusions and raw tests below as an "answer" but they're not a full ...
0
votes
2
answers
232
views
How to expand variable within a single-quoted argument?
I am trying to perform the following without luck:
SORT_BY='-k3,3r -k2,2 -k1,1r'
awk 'NR<4{print $0;next}{print $0 | sort '"${SORT_BY}"' -t"~"}'
I have tried with all sorts of quotes, unquote, ...
2
votes
2
answers
369
views
What is the right way to quote nested parameter expansions?
When dealing with with nested parameter expansions, which of these is the correct way to quote things?
This one:
var="${var#"${var%%[![:space:]]*}"}"
Or this one:
var="${var#${var%%[![:space:]]*}}"...
0
votes
1
answer
87
views
Find: Substitute expression with a variable
$ find -name "Bik*"
./Biking
./Biking/Unsync/Biking.md.~6~
./Biking/Rendered/Biking.gen.html
./Biking/Biking.md
Now when I substitute expression with a variable as follows:
$ a='-name "Bik*"'
$ ...
-2
votes
2
answers
4k
views
How to execute a command that has many nested single and double quotes with a quoted variable in bash
Here is my simple script
#!/bin/sh
thefile=/home/ark/arkserver/ShooterGame/Saved/SaveIsland/1288804998.arktribe
while inotifywait "${thefile}" ; do
a=\"`strings ${thefile} | tail -n 5 | head -n ...
3
votes
1
answer
4k
views
Is `echo $TEST` expanding an asterisk in the variable a bug? [duplicate]
Is this a Bash bug?
$ mkdir test && cd test && echo "a" > "some.file"
test$ echo '*'
*
test$ TEST=$(echo '*')
test$ echo $TEST
some.file
Why is the second output the resolution of ...
4
votes
1
answer
939
views
readlink literal vs variable
Using BASH: the answer is probably obvious but, not for me.
> echo $PWD
/root/fcm
> readlink -f ~
/root
> # but then with a variable or literal
> a='~'
> readlink -f $a
/root/fcm/~
>...
6
votes
4
answers
18k
views
Backslash in variable substitution in Bash
I was working on a Bash script to help partition a hard drive correctly, and I came across a strange problem where I had to append a number to a variable. It took me a while to get the outcome right ...
3
votes
1
answer
1k
views
Double Quotes in Bash's variable substitution
I am trying to configure some software packages with a script thereby I got the following problem. Assume that the environment variable PREFIX is set to the location where I plan to install the ...
9
votes
4
answers
7k
views
Can I reload variable in a watch command?
Part of my job involves some data handling. One of the tasks is to 'flatten' a set of directories (which we'll call Dir for now), and copy them to a new location called DirFlat.
This can take a long ...
0
votes
2
answers
602
views
Reading output of command into variable in shell, splits text at every white space not just newline
I'm using sh (not bash/csh) on FreeBSD 11, and I don't understand this:
In console
Command: zpool status -v
Result:
pool: My_pool
state: ONLINE
status: One or more devices is currently being ...
1
vote
2
answers
2k
views
Use sed command with variables
I have tried every possible solution available on the Stack Overflow and its related websites but did not find any solution. I spent a reasonable amount of time on this issue and am finally posting ...
5
votes
3
answers
8k
views
Spaces for variables in bash script
I have a space in one of the directory names. I want to list a file under it from a bash script. Here is my script:
fpath="${HOME}/\"New Folder\"/foobar.txt"
echo "fpath=(${fpath})"
#fpath="${HOME}/$...