Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking for a way to manipulate some env var, which will be available for processes spawned by bash.

Something like the below (of course, the syntax is not correct)

/bin/bash VAR_X=2

and then later command being run from bash script can do

if [ "$ENV_VAR_X" = 2 ] .. 

Notice that I'm invoking bash from a windows Console2/Msys setup, so doing VAR_X=2 bash is not an option.

Does anyone know how it can be done?

share|improve this question
up vote 1 down vote accepted


env VAR_X=2 command

This would pre-define the variable named VAR_X (only if you runs bash as current shell)


To fix that on Windows system, simply create a cmd script, that set the variable prior to execution, or in My Computers->Advanced->Environment Variables set a global one,

@echo off
set VAR_X=2
share|improve this answer
@user1480524 see if the update hepls – warl0ck Dec 30 '12 at 7:38
Thanks, that's what I needed :-) – user1480524 Dec 30 '12 at 16:25


    yourVar="your value" /bin/bash

then you're in bash, or running any other program, and $yourVar is your value

share|improve this answer
I didn't give enough info - I'm running Console2/Msys setup, so prepending the var to the bash invocation is not possible. I updated the question accordingly. – user1480524 Dec 30 '12 at 7:35
    export yourVar="your value"

will also make the variable available to subprocesses.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.