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

All Questions

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, ...
Whimusical's user avatar
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
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
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
1 vote
1 answer
8k views

Passing a variable argument to egrep in a bash script

I have a script, myScript, which is trying to egrep the script argument in a file. Somehow variable expansion isn't working properly with the egrep command. I believe I've isolated the problem ...
Leo Simon's user avatar
  • 453
0 votes
1 answer
3k views

Searching path as search pattern in grep command

I have saved the path in the variable . var="/home/myfolder/subfolder" Need to search whether the path in available in a text file using grep. grep -l '${var}' * >abc.txt I'm trying to list ...
VRVigneshwara's user avatar
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
2 votes
2 answers
211 views

variable substitution in CLI and for loops

I am pretty sure this has been asked already in some form, I just cannot come up with a good find to search it. I want to have a script that do things N times and to which I can pass as a variable ...
Rho Phi's user avatar
  • 319
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
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
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
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