Why isn't a read variable being found in my bash script? [duplicate]
This question already has an answer here:
Why should there be a space after '[' and before ']' in Bash?
4 answers
if statement error in bash [duplicate]
2 answers
I'm not sure why I keep getting a not found error for a variable read from the console. I'm trying to test if the variable read (var) is equal to "q" or not with the if-then-else statement.
I have tried making "q" a variable (as it is now) and leaving it as a string inside the control structure. Both yielded the same result.
q="q"
read var
echo "var = $var"
echo "q = $q"
if ["$var" == "$q"]
then
echo "if completed"
else
echo "else complete"
fi
If I type in "q" I want "if completed" to be output but I keep getting:
"/home/adamgeds/Projects/bash.sh: 13: /home/adamgeds/Projects/bash.sh: [q: not found
else complete"
(I should also mention that I believe the "q" in the error refers to $var and not $q... if that helps.)
bash ubuntu
marked as duplicate by Cyrus
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 31 '18 at 20:52
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Why should there be a space after '[' and before ']' in Bash?
4 answers
if statement error in bash [duplicate]
2 answers
I'm not sure why I keep getting a not found error for a variable read from the console. I'm trying to test if the variable read (var) is equal to "q" or not with the if-then-else statement.
I have tried making "q" a variable (as it is now) and leaving it as a string inside the control structure. Both yielded the same result.
q="q"
read var
echo "var = $var"
echo "q = $q"
if ["$var" == "$q"]
then
echo "if completed"
else
echo "else complete"
fi
If I type in "q" I want "if completed" to be output but I keep getting:
"/home/adamgeds/Projects/bash.sh: 13: /home/adamgeds/Projects/bash.sh: [q: not found
else complete"
(I should also mention that I believe the "q" in the error refers to $var and not $q... if that helps.)
bash ubuntu
marked as duplicate by Cyrus
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 31 '18 at 20:52
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
Add a shebang and then paste your script there: shellcheck.net
– Cyrus
Dec 31 '18 at 20:50
Perfect thank you.
– Z0S0
Dec 31 '18 at 21:02
add a comment |
This question already has an answer here:
Why should there be a space after '[' and before ']' in Bash?
4 answers
if statement error in bash [duplicate]
2 answers
I'm not sure why I keep getting a not found error for a variable read from the console. I'm trying to test if the variable read (var) is equal to "q" or not with the if-then-else statement.
I have tried making "q" a variable (as it is now) and leaving it as a string inside the control structure. Both yielded the same result.
q="q"
read var
echo "var = $var"
echo "q = $q"
if ["$var" == "$q"]
then
echo "if completed"
else
echo "else complete"
fi
If I type in "q" I want "if completed" to be output but I keep getting:
"/home/adamgeds/Projects/bash.sh: 13: /home/adamgeds/Projects/bash.sh: [q: not found
else complete"
(I should also mention that I believe the "q" in the error refers to $var and not $q... if that helps.)
bash ubuntu
This question already has an answer here:
Why should there be a space after '[' and before ']' in Bash?
4 answers
if statement error in bash [duplicate]
2 answers
I'm not sure why I keep getting a not found error for a variable read from the console. I'm trying to test if the variable read (var) is equal to "q" or not with the if-then-else statement.
I have tried making "q" a variable (as it is now) and leaving it as a string inside the control structure. Both yielded the same result.
q="q"
read var
echo "var = $var"
echo "q = $q"
if ["$var" == "$q"]
then
echo "if completed"
else
echo "else complete"
fi
If I type in "q" I want "if completed" to be output but I keep getting:
"/home/adamgeds/Projects/bash.sh: 13: /home/adamgeds/Projects/bash.sh: [q: not found
else complete"
(I should also mention that I believe the "q" in the error refers to $var and not $q... if that helps.)
This question already has an answer here:
Why should there be a space after '[' and before ']' in Bash?
4 answers
if statement error in bash [duplicate]
2 answers
bash ubuntu
bash ubuntu
edited Dec 31 '18 at 20:50
Flimzy
38.7k106597
38.7k106597
asked Dec 31 '18 at 20:49
Z0S0Z0S0
1
1
marked as duplicate by Cyrus
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 31 '18 at 20:52
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Cyrus
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 31 '18 at 20:52
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
Add a shebang and then paste your script there: shellcheck.net
– Cyrus
Dec 31 '18 at 20:50
Perfect thank you.
– Z0S0
Dec 31 '18 at 21:02
add a comment |
1
Add a shebang and then paste your script there: shellcheck.net
– Cyrus
Dec 31 '18 at 20:50
Perfect thank you.
– Z0S0
Dec 31 '18 at 21:02
1
1
Add a shebang and then paste your script there: shellcheck.net
– Cyrus
Dec 31 '18 at 20:50
Add a shebang and then paste your script there: shellcheck.net
– Cyrus
Dec 31 '18 at 20:50
Perfect thank you.
– Z0S0
Dec 31 '18 at 21:02
Perfect thank you.
– Z0S0
Dec 31 '18 at 21:02
add a comment |
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
1
Add a shebang and then paste your script there: shellcheck.net
– Cyrus
Dec 31 '18 at 20:50
Perfect thank you.
– Z0S0
Dec 31 '18 at 21:02