Thomas
Thomas

Reputation: 8930

What is =C in bash?

I read in a script somewhere :

a_var=C ls

I tried it. This executes ls (I see the content of the current directory) and leaves a_var empty. What is this =C in bash ? It is the first time I see it.

Upvotes: 2

Views: 113

Answers (2)

Oerd
Oerd

Reputation: 2303

The line var_a=C ls is a bash command.

Any Bash command can set environment variables local to the commands executing environment, these environment variables (var_a in your case) won't exist after execution. This is, for example, often used when running make to specify options like a different compiler than the default, or in curl like so:

$ CC=~/bin/my_own_cc make
$ http_proxy=http://proxy_server:8080 curl http://www.google.com

When run like this, make will user ~/bin/my_own_cc instead of the default C compiler and curl will know to use a proxy when retrieving http://google.com.

These commands will not pollute the executing environment with otherwise unnecessary variables.

That said, in your example, this doesn't have any side effects.

Upvotes: 1

Johannes H.
Johannes H.

Reputation: 6167

This will set the environment-variable a_var to "C" in the environment ls runs in. Most likely this was used to actually set the collation ls uses to influence sorting (LANG=C ls or LC_COLLATE=C ls).

Using C as collation for ls will sort files case-sensitive, meaning files starting with a-z come after A-Z. SOme other collations may have additional rules, such as ignoring dots or treating umlauts as vowels - C doesn't have anything like this.

Upvotes: 4

Related Questions