0

Why is my vagrant transforming this provision line:

echo "eval \"\$(starship init bash)\"" >> ~/.bashrc

in this line in .bashrc ?

eval  __main() { local major="${BASH_VERSINFO[0]}" local minor="${BASH_VERSINFO[1]}" if ((major > 4)) || { ((major == 4)) && ((minor >= 1)); }; then source <(/usr/local/bin/starship init bash --print-full-init) else source /dev/stdin <<<"$(/usr/local/bin/starship init bash --print-full-init)" fi } __main unset -f __main 

This is the result of executing $(starship init bash) but it shouldn't be executing, once I'm only doing an echo.

How can I avoid it ?

Edit

With single quotes the result is the same, yet formatted.

I tried to run the command echo "eval \"\$(starship init bash)\"" >> ~/.bashrc inside the VM and it worked perfectly.

4
  • 1
    Try using single-quotes (') instead of double-quotes (").
    – harrymc
    Commented Oct 2, 2022 at 16:33
  • See the edit I made Commented Oct 2, 2022 at 18:36
  • Strange, what is the result with single quotes?
    – harrymc
    Commented Oct 2, 2022 at 18:43
  • @harrymc as I said in the edit, the result with single quotes is the same, yet formatted. Instead of a single line, the result apears indented in serveral lines. Commented Oct 3, 2022 at 17:37

1 Answer 1

0

There were 2 problems:

First, as @harrymc said, I should have used single quotes. But instead of using single quotes in the outside of the string I used them like this:

echo "eval \'\$(starship init bash)\'" >> ~/.bashrc

That continued to created an expanded string instead of what I was intending.

The 2nd problem is that I forgot the -e switch in echo which disabled the interpretation of backslash escapes.

So the correct line is this:

echo -e 'eval \"\$(starship init bash)\"' >> ~/.bashrc

Thanks to all that helped.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .