0

I came across a Python command line like this:

CITYSCAPES_DATASET=/path/to/abovementioned/cityscapes python cityscapesscripts/preparation/createTrainIdLabelImgs.py

I tried to read the python docs on command line, but I couldn't find out what that command line grammar is.

Looks like it's about setting some Environment variable(or Shell variable), but I'm not sure.

What does it mean, and what is the exact grammar?

1
  • 1
    Consult the man page for your shell (e.g. bash, zsh). Commented Feb 10, 2021 at 2:51

1 Answer 1

1

It has nothing to do with python. In general,

var=value cmd

invokes cmd with var set to value in its environment. It is a simple way to set an environment variable for a single command.

The specifics are given in https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_01:

A "simple command" is a sequence of optional variable assignments and redirections, in any sequence, optionally followed by words and redirections, terminated by a control operator.

When a given simple command is required to be executed (that is, when any conditional construct such as an AND-OR list or a case statement has not bypassed the simple command), the following expansions, assignments, and redirections shall all be performed from the beginning of the command text to the end:

The words that are recognized as variable assignments or redirections according to Shell Grammar Rules are saved for processing in steps 3 and 4.

The words that are not variable assignments or redirections shall be expanded. If any fields remain following their expansion, the first field shall be considered the command name and remaining fields are the arguments for the command.

Redirections shall be performed as described in Redirection.

Each variable assignment shall be expanded for tilde expansion, parameter expansion, command substitution, arithmetic expansion, and quote removal prior to assigning the value.

Sign up to request clarification or add additional context in comments.

1 Comment

... set an environment variable just for the environment of that command.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.