Skip to main content

All 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
ll cool's user avatar
  • 31
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 ...
falky's user avatar
  • 189
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 => ...
falky's user avatar
  • 189
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 ...
bit's user avatar
  • 1,116
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 ...
wshyang's user avatar
  • 11
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
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 ...
user avatar
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'...
Display name's user avatar
  • 1,317
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-...
Philip Kirkbride's user avatar
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 "$...
Chris Stryczynski's user avatar
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 ...
luis.madrigal's user avatar
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 $...
cdnszip's user avatar
  • 253
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 ...
Balagopal Komarath's user avatar
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/...
Anonymous Platypus's user avatar
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 ...
ness's user avatar
  • 23

15 30 50 per page