2

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?

1

Try

env VAR_X=2 command

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

EDIT

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
command
  • @user1480524 see if the update hepls – daisy Dec 30 '12 at 7:38
0

simply

    yourVar="your value" /bin/bash

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

  • 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
0
    export yourVar="your value"

will also make the variable available to subprocesses.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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