All Questions
32
questions
3
votes
2
answers
280
views
Why does the command echo `echo \\\\\\\z` in bash script print \\z instead of \\\z?
The command
echo `echo \\\\\\\z`
is from this book , I don’t understand why it prints
\\z
when it get executed via the bash script.
I think it should print
\\\z
5
votes
3
answers
5k
views
Escaping double quotes inside command substitution
I am attempting to write a simple bash parser. I am following the steps in this wiki. One of the assumptions I make is that I can do a pass over the entire input string and remove all single and ...
1
vote
1
answer
973
views
Command substitution inside double quotes
I am attempting to write a bash parser. Many resources have referred to this wiki
One area I am getting stuck is why the following would work
echo "$(echo "hi")" # output => ...
6
votes
4
answers
6k
views
How to prevent command substitution on the command line?
I find that when writing text as input to another program, any command substitutions in double quotes within the intended text are interpreted and expanded by the shell
The links in the answer here ...
1
vote
2
answers
4k
views
Bash: Escaping double quotes in $() command substitution [duplicate]
I am having trouble wrapping my head around how command substitution works when part of the command's parameters come from a variable.
To illustrate, I'll just present a series of commands:
I'll ...
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 ...
27
votes
1
answer
9k
views
What's the right way to quote $(command $arg)?
It's high time to solve this conundrum that's been bothering me for years...
I've been meeting this from time to time and thought this is the way to go:
$(comm "$(arg)")
And thought my view was ...
0
votes
1
answer
53
views
Why doesn't this command work like I expect? [closed]
cat $(echo this\\ list)
Seems like it should be the same as
cat this\ list
but it isn't.
I know that I can use
cat "$(echo this\\ list)"
but then I can't echo multiple files into cat.
Why doesn'...
0
votes
1
answer
1k
views
Subshell inside quotes
I'm writing a small shell script like this:
curl -X POST --header 'Bearer "$(printf user:pass | base64)"' 'https://api.com/v1/auth'
To debug I switched to echo:
echo 'Bearer "$(printf remote-key-...
2
votes
1
answer
394
views
Strange output with command subtitution using backticks in bash script
echo "testing:"
PROXY_URL="/proxyurl/"
proxyUrlSedEscaped=`echo "$PROXY_URL" | sed -e 's/[\/&]/\\&/g'`
echo "$PROXY_URL" | sed -e 's/[\/&]/\\&/g'
echo "$...
6
votes
2
answers
4k
views
Is there a way to execute code in the command line prompt (PS1) without using backticks?
I am using this piece of code directly in the command prompt (PS1), and it tells me whether the previous command executed correctly.
PS1="\`if [ \$? = 0 ]; then echo -e \"\e[1;32m[⚡️ ]\"\e[0m; else ...
1
vote
1
answer
1k
views
Alias accepting variables from the result of evaluation [duplicate]
I was trying to define an alias that helps me to cd to the directory that is created most recently, and I'm using the following in my .bashrc:
alias cdlatest="latestdir=$(ls -td -- */|head -n 1); cd $...
8
votes
1
answer
2k
views
Filenames with spaces in backtick substitution
Suppose I have a file containing a space in its name such as with space. What should cmd output in the below snippet for ls to accept 'with space' as argument?
$ ls `cmd`
I tried ls `echo 'with ...
0
votes
3
answers
1k
views
issue with back quotes inside while loop when running a command over ssh
This question is a bit complicated. I will try to explain in detail.
I have two machines, one is local and other say 192.168.1.2. I have set the following variables in my local machine
CHECK="/home/...
2
votes
3
answers
1k
views
Bash: Quotation in command substitution
In short, I want to use directories listed by a command in a find command:
find $(produces_dir_names --options...) -find-options...
The problem comes with white space in the directory names. I ...