Behavior I don't understand in bash

bash

Solution

The line `$ echo $myvariable` is being parsed by first substituting the contents of `$myvariable` into the line, then running the line. So when the line is parsed by bash, it looks like `$ echo ab*`.

If you `$ echo "$myvariable"`, you will get the behavior you want.

Problem

I have a folder with 3 dummy files: ab0, ab1 and ab2. ``` $ echo ab* ab0 ab1 ab2 $ myvariable=ab* $ echo $myvariable ab0 ab1 ab2 $ echo 'ab*' ab* ``` Up to here, I think I understand. But: ``` $ myvariable='ab*' $ echo $myvariable ab0 ab1 ab2 ``` I was expecting `ab*`. This means that there is a basic that I don't understand. I've been searching for single vs double quotes, expansion and more in bash tutorials and manuals but I don't get it yet.

Original source