Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does bash insert quotes I didn't ask for?

Tags:

bash

shell

Can someone explain this to me, please?

$ set -x
$ export X="--vendor Bleep\ Bloop"; echo $X
+ export 'X=--vendor Bleep\ Bloop'
+ X='--vendor Bleep\ Bloop'
+ echo --vendor 'Bleep\' Bloop
--vendor Bleep\ Bloop
$

Specifically, why does the echo line insert ' characters that I didn't ask for, and why does it leave the string looking unterminated?

like image 616
scoates Avatar asked Jan 08 '13 17:01

scoates


1 Answers

Understanding Shell Expansions

Bash performs shell expansions in a set order. The -x flag allows you to see the intermediate results of the steps that Bash takes as it tokenizes and expands the words that compose the input line.

In other words, the output is operating as designed. Unless you're trying to debug tokenization, word-splitting, or expansion, the intermediate results shouldn't really matter to you.

like image 194
Todd A. Jacobs Avatar answered Oct 21 '22 14:10

Todd A. Jacobs