Skip to main content
The 2024 Developer Survey results are live! See the results

All 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 $ ...
Pandya's user avatar
  • 24.9k
19 votes
2 answers
95k views

Passing a variable to sed [duplicate]

I cannot not use a shell variable in sed in the $NUMBER form. I have this line in my shell script: cat shared.txt sed 's/whatever1/$2 ... whatever2/' > shared2.txt The result in shared2.txt looks ...
user2013619's user avatar
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 ...
AncientSwordRage's user avatar
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 ...
Wildcard's user avatar
  • 36.8k
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 ...
user avatar
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}/$...
kmad1729's user avatar
  • 153
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/~ >...
fcm's user avatar
  • 447
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 ...
Roel Van de Paar's user avatar
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 ...
Nordine Lotfi's user avatar
3 votes
3 answers
3k views

Variable expansion in Bash

I tried the following commands variable='one|name' echo $variable The output is one|name whereas echo one|name gives an error No command 'name' found. This is reasonable because bash treats | as a ...
nitishch's user avatar
  • 461
3 votes
1 answer
3k views

variable expansion within command substitution over SSH bash 4.X

I want to do this ssh ${w100user}@web100 'ls -l "$(grep "${1}" /etc/pure-ftpd/pureftpd.passwd|cut -d':' -f6)"' Which obviously performs an ssh session to server web100 as w100user and then greps ...
Gregg Leventhal's user avatar
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 ...
M.K. aka Grisu's user avatar
2 votes
2 answers
4k views

Environment variable not expanded inside the command line argument

I have a file user-pid.out2 which has "usernumber" and "process id" as two columns. based on usernumber I want to find corresponding process id. the first two lines below does not show the output ...
Anil's user avatar
  • 21
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:]]*}}"...
Harold Fischer's user avatar
2 votes
1 answer
5k views

bash: export: `--wait': not a valid identifier

When I run git-sh from my terminal it works fine. But I get the following warning. bash: export: `--wait': not a valid identifier What is this and how do I get rid of it?
ShivamD's user avatar
  • 141

15 30 50 per page