1

I have the following script

echo ".*/tools/.*"
var=$(echo ".*/tools/.*")
echo $var

The output of this is

.*/tools/.*
./tools/. ./tools/..

I would expect the output of this to be

.*/tools/.*
.*/tools/.*

Why is var being assigned multiple values? And how can I have it output the expected value?

tools is a folder in my current working directory, so I assume it has something to do with that.

GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)

Dillydill123
  • 693
  • 7
  • 22
  • 3
    Not when assigned, when echoed without enough quotes. The assignment is fine. The `echo` at the end is not. – Charles Duffy May 24 '23 at 13:14
  • Well, `var=$(echo ".*/tools/.*")` isn't _fine_, exactly -- it's incredibly inefficient (you're forking off a subprocess and capturing its output through a pipe just to achieve the effect of `var=".*/tools/.*"`) – Charles Duffy May 24 '23 at 13:16
  • The associated question answers mine. I could not for the life of me google the correct words to find it. Thanks for the insight. – Dillydill123 May 24 '23 at 13:17

0 Answers0