EN VI

Bash - Using Inline variables in command line commands?

2024-03-12 22:30:04
How to Bash - Using Inline variables in command line commands

The command below repeats the word "stage" three times. Is there a way to set a variable at the beginning of the command and then use it further on?

AWS_REGION="us-west-2" AWS_PROFILE="stage" mvn clean test -Dtest=KarateRunner#stage -DargLine="-Dkarate.env=stage"

Something like:

set env=stage && AWS_REGION="us-west-2" AWS_PROFILE="%env%" mvn clean test -Dtest=KarateRunner#%env% -DargLine="-Dkarate.env=%env%"

But this doesn't work, obviously.

Solution:

You need:

env=stage; AWS_REGION="us-west-2" AWS_PROFILE="$env" mvn clean test -Dtest="KarateRunner#$env" -DargLine="-Dkarate.env=$env"
Answer

Login


Forgot Your Password?

Create Account


Lost your password? Please enter your email address. You will receive a link to create a new password.

Reset Password

Back to login