bash script to check values of variables and assign if not defaultUsing “${a:-b}” for variable assignment...
Why were the Night's Watch required to be celibate?
What is the correct expression of 10/20, 20/30, 30/40 etc?
Credit card offering 0.5 miles for every cent rounded up. Too good to be true?
How can I add depth to my story or how do I determine if my story already has depth?
Is it OK to bring delicacies from hometown as tokens of gratitude for an out-of-town interview?
Why does MS SQL allow you to create an illegal column?
Opposite of "Squeaky wheel gets the grease"
You've spoiled/damaged the card
Is there any Biblical Basis for 400 years of silence between Old and New Testament?
Does Peach's float negate shorthop knockback multipliers?
Short story written from alien perspective with this line: "It's too bright to look at, so they don't"
Get value of the passed argument to script importing variables from another script
Is it a problem that pull requests are approved without any comments
Will TSA allow me to carry a CPAP?
Incremental Ranges!
How to provide realism without making readers think grimdark
How can Iron Man's suit withstand this?
Computing the differentials in the Adams spectral sequence
What is the best option to connect old computer to modern TV
Can an old DSLR be upgraded to match modern smartphone image quality
Strange math syntax in old basic listing
What is a simple, physical situation where complex numbers emerge naturally?
Do adult Russians normally hand-write Cyrillic as cursive or as block letters?
Sucuri detects malware on wordpress but I can't find the malicious code
bash script to check values of variables and assign if not default
Using “${a:-b}” for variable assignment in scriptsGraphically ask for password in a bash script and retain default sudo timeout settingBash scripting to scan files for words and create reportBash script with ssh not returning value of variables
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
Team,
I have 2 environment variables that can be change by user input in jenkins job before running script below. the script has them statically defaulted to certain values. But if the env variable is having a change value from jenkins then i want to use env variable value that is provided by jenkins and not static that is defined in the code.
Threads=6 #< default to be used
BlockSize=90 #< default to be used
for var in "$Threads" "$BlockSize"; do
echo var
if $var != "Default": #< jenkins default is "Default"
echo "variable is custom and changed in environment"
Threads=$Thread
else
echo "Using defined variables from this script and skipping env variables"
done;
run_func $Threads $BlockSize
So, if user specifies Threads=7, then I want to use 7 while running the function and not 6. so, my concern is after defining a variable inside script, how can i again compare it with same variable exported in ENV?
ex: below is expected runs with new value of thread
run-func 7 90
Error:
./replace-var.sh: line 16: syntax error near unexpected token `done'
./replace-var.sh: line 16: `done;'
bash
New contributor
add a comment |
Team,
I have 2 environment variables that can be change by user input in jenkins job before running script below. the script has them statically defaulted to certain values. But if the env variable is having a change value from jenkins then i want to use env variable value that is provided by jenkins and not static that is defined in the code.
Threads=6 #< default to be used
BlockSize=90 #< default to be used
for var in "$Threads" "$BlockSize"; do
echo var
if $var != "Default": #< jenkins default is "Default"
echo "variable is custom and changed in environment"
Threads=$Thread
else
echo "Using defined variables from this script and skipping env variables"
done;
run_func $Threads $BlockSize
So, if user specifies Threads=7, then I want to use 7 while running the function and not 6. so, my concern is after defining a variable inside script, how can i again compare it with same variable exported in ENV?
ex: below is expected runs with new value of thread
run-func 7 90
Error:
./replace-var.sh: line 16: syntax error near unexpected token `done'
./replace-var.sh: line 16: `done;'
bash
New contributor
Is this a question? Does your code not do what you describe? Please provide details of what did not work, what you expect to happen, etc.
– 0xSheepdog
1 hour ago
Are you perhaps asking about this construct? Using “${a:-b}” for variable assignment in scripts
– steeldriver
57 mins ago
1
Your code won't even run. That's not the correct syntax forif
, nor is it that how you test for inequality.
– muru
52 mins ago
Are you talking about the user setting an environment variable, or are you talking about command-line arguments? If the former, what do you want to happen if the user explicitly setsThreads=6
orBlockSize=90
? If the letter, are you really asking how to test whether$1
is6
?
– Scott
50 mins ago
The user is jenkins and he can over ride the default value that is set in the script. So, I am trying to see if value is changed by jenkins user then use it in script instead of the default one already inside script.
– fma abd
48 mins ago
add a comment |
Team,
I have 2 environment variables that can be change by user input in jenkins job before running script below. the script has them statically defaulted to certain values. But if the env variable is having a change value from jenkins then i want to use env variable value that is provided by jenkins and not static that is defined in the code.
Threads=6 #< default to be used
BlockSize=90 #< default to be used
for var in "$Threads" "$BlockSize"; do
echo var
if $var != "Default": #< jenkins default is "Default"
echo "variable is custom and changed in environment"
Threads=$Thread
else
echo "Using defined variables from this script and skipping env variables"
done;
run_func $Threads $BlockSize
So, if user specifies Threads=7, then I want to use 7 while running the function and not 6. so, my concern is after defining a variable inside script, how can i again compare it with same variable exported in ENV?
ex: below is expected runs with new value of thread
run-func 7 90
Error:
./replace-var.sh: line 16: syntax error near unexpected token `done'
./replace-var.sh: line 16: `done;'
bash
New contributor
Team,
I have 2 environment variables that can be change by user input in jenkins job before running script below. the script has them statically defaulted to certain values. But if the env variable is having a change value from jenkins then i want to use env variable value that is provided by jenkins and not static that is defined in the code.
Threads=6 #< default to be used
BlockSize=90 #< default to be used
for var in "$Threads" "$BlockSize"; do
echo var
if $var != "Default": #< jenkins default is "Default"
echo "variable is custom and changed in environment"
Threads=$Thread
else
echo "Using defined variables from this script and skipping env variables"
done;
run_func $Threads $BlockSize
So, if user specifies Threads=7, then I want to use 7 while running the function and not 6. so, my concern is after defining a variable inside script, how can i again compare it with same variable exported in ENV?
ex: below is expected runs with new value of thread
run-func 7 90
Error:
./replace-var.sh: line 16: syntax error near unexpected token `done'
./replace-var.sh: line 16: `done;'
bash
bash
New contributor
New contributor
edited 41 mins ago
fma abd
New contributor
asked 1 hour ago
fma abdfma abd
11
11
New contributor
New contributor
Is this a question? Does your code not do what you describe? Please provide details of what did not work, what you expect to happen, etc.
– 0xSheepdog
1 hour ago
Are you perhaps asking about this construct? Using “${a:-b}” for variable assignment in scripts
– steeldriver
57 mins ago
1
Your code won't even run. That's not the correct syntax forif
, nor is it that how you test for inequality.
– muru
52 mins ago
Are you talking about the user setting an environment variable, or are you talking about command-line arguments? If the former, what do you want to happen if the user explicitly setsThreads=6
orBlockSize=90
? If the letter, are you really asking how to test whether$1
is6
?
– Scott
50 mins ago
The user is jenkins and he can over ride the default value that is set in the script. So, I am trying to see if value is changed by jenkins user then use it in script instead of the default one already inside script.
– fma abd
48 mins ago
add a comment |
Is this a question? Does your code not do what you describe? Please provide details of what did not work, what you expect to happen, etc.
– 0xSheepdog
1 hour ago
Are you perhaps asking about this construct? Using “${a:-b}” for variable assignment in scripts
– steeldriver
57 mins ago
1
Your code won't even run. That's not the correct syntax forif
, nor is it that how you test for inequality.
– muru
52 mins ago
Are you talking about the user setting an environment variable, or are you talking about command-line arguments? If the former, what do you want to happen if the user explicitly setsThreads=6
orBlockSize=90
? If the letter, are you really asking how to test whether$1
is6
?
– Scott
50 mins ago
The user is jenkins and he can over ride the default value that is set in the script. So, I am trying to see if value is changed by jenkins user then use it in script instead of the default one already inside script.
– fma abd
48 mins ago
Is this a question? Does your code not do what you describe? Please provide details of what did not work, what you expect to happen, etc.
– 0xSheepdog
1 hour ago
Is this a question? Does your code not do what you describe? Please provide details of what did not work, what you expect to happen, etc.
– 0xSheepdog
1 hour ago
Are you perhaps asking about this construct? Using “${a:-b}” for variable assignment in scripts
– steeldriver
57 mins ago
Are you perhaps asking about this construct? Using “${a:-b}” for variable assignment in scripts
– steeldriver
57 mins ago
1
1
Your code won't even run. That's not the correct syntax for
if
, nor is it that how you test for inequality.– muru
52 mins ago
Your code won't even run. That's not the correct syntax for
if
, nor is it that how you test for inequality.– muru
52 mins ago
Are you talking about the user setting an environment variable, or are you talking about command-line arguments? If the former, what do you want to happen if the user explicitly sets
Threads=6
or BlockSize=90
? If the letter, are you really asking how to test whether $1
is 6
?– Scott
50 mins ago
Are you talking about the user setting an environment variable, or are you talking about command-line arguments? If the former, what do you want to happen if the user explicitly sets
Threads=6
or BlockSize=90
? If the letter, are you really asking how to test whether $1
is 6
?– Scott
50 mins ago
The user is jenkins and he can over ride the default value that is set in the script. So, I am trying to see if value is changed by jenkins user then use it in script instead of the default one already inside script.
– fma abd
48 mins ago
The user is jenkins and he can over ride the default value that is set in the script. So, I am trying to see if value is changed by jenkins user then use it in script instead of the default one already inside script.
– fma abd
48 mins ago
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
fma abd is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f522079%2fbash-script-to-check-values-of-variables-and-assign-if-not-default%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
fma abd is a new contributor. Be nice, and check out our Code of Conduct.
fma abd is a new contributor. Be nice, and check out our Code of Conduct.
fma abd is a new contributor. Be nice, and check out our Code of Conduct.
fma abd is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f522079%2fbash-script-to-check-values-of-variables-and-assign-if-not-default%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Is this a question? Does your code not do what you describe? Please provide details of what did not work, what you expect to happen, etc.
– 0xSheepdog
1 hour ago
Are you perhaps asking about this construct? Using “${a:-b}” for variable assignment in scripts
– steeldriver
57 mins ago
1
Your code won't even run. That's not the correct syntax for
if
, nor is it that how you test for inequality.– muru
52 mins ago
Are you talking about the user setting an environment variable, or are you talking about command-line arguments? If the former, what do you want to happen if the user explicitly sets
Threads=6
orBlockSize=90
? If the letter, are you really asking how to test whether$1
is6
?– Scott
50 mins ago
The user is jenkins and he can over ride the default value that is set in the script. So, I am trying to see if value is changed by jenkins user then use it in script instead of the default one already inside script.
– fma abd
48 mins ago