All Questions
14
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, ...
-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 ...
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 ...
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 ...
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}/$...
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/~
>...
1
vote
1
answer
2k
views
bash adds apostrophes to expanded variable
I am reading in a file inside my bash script where each line consists of multiple columns like this:
ANSIBLE 'first run' '--diff --extra-vars "client=yes fast=no"'
As you can see, the line consists ...
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
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 ...
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 ...
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 ...
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?