line 7: [: missing `]' I have that error How do I fix it? I have indented [duplicate]
This question already has an answer here:
Brackets in if condition: why am I getting syntax errors without whitespace?
3 answers
#!/bin/bash
until ["$userIn" = "j"]
do
echo "Welcome to the Menu_Script Program!"
echo
echo "Menu Options"
echo "Please Select an Option."
echo
echo
echo "Press a to use the Emailer Program"
echo
echo "Press b to Display the Users that are Currently Logged On"
echo
echo "Press c to Display the Current Date and Time"
echo
echo "Press d to Display the Months Calendar"
echo
echo "Press e to Display the name of the Working Directory"
echo
echo "Press f to Display the Contents of the Working Directory"
echo
echo "Press g to Find the IP of a Web Address"
echo
echo "Press h to See your Fortune"
echo
echo "Press i to Display a file on the screen"
echo
echo
echo "Press j to Exit this Menu"
echo
echo "Press m to show the Menu Options again"
echo
read mOption
case "$mOption" in
a|A)
echo "Welcome to the Emailer Program"
echo
echo "Please enter the content of your message and press <ENTER>:"
read $mContent
echo
echo "Please enter the email address of the recipient and press <ENTER>:"
read $mAddress
echo
echo "Is there a file to be attached to this message? Press Y/N:"
read $ATTACH
echo
if ["$ATTACH"="Y"|"y"]
then
echo "Please enter the name of the FILE to be attached:"
read $mAttach
mail -s "$mContent" "$mAddress"<"$mAttach"
echo
echo "Your mail will be sent with the attachment."
echo
else
mail -s "$mContent""$mAddress"
echo
echo "Your mail will be sent without an attachment."
echo
fi
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
b|B)
echo "Here is a list of users that are currently logged on:"
w
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
c|B)
echo "The current date and time:"
date
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
d|D)
echo "Here is the current Months of the calendar:"
cal
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
e|E)
echo "Here is the name of the Working Directory:"
pwd
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
f|F)
echo "Here is the Contents of the Working Directory"
ls
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
g|G)
echo "Please type a Web Address whose IP Address you"
echo "would like to find, then press <ENTER>:"
read $mWeb
echo
echo "Here is the IP Address Information:"
nslookup $mWeb
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
h|H)
echo "Here is your Fortune for today!"
echo
fortune
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
i|I)
echo "Please enter the name of the file that you want to be displayed:"
read $mFile
echo
echo "Here is your file:"
cat $mFile
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
j|J)
echo "Thank you for using the Menu_Script Program!"
userIn = j
echo
;;
m|M)
echo "Menu Options"
echo "Please Select an Option:"
echo
echo
echo "Press a to use the Emailer Program"
echo
echo "Press b to Display the Users that are Currently Logged On"
echo
echo "Press c to Display the Current Date and Time"
echo
echo "Press d to Display the Months Calendar"
echo
echo "Press e to Display the name of the Working Directory"
echo
echo "Press f to Display the Contents of the Working Directory"
echo
echo "Press g to Find the IP of a Web Address"
echo
echo "Press h to See your Fortune"
echo
echo "Press i to Display a file on the screen"
echo
echo
echo "Press j to Exit this Menu"
echo
echo "Press m to show the Menu Options again"
echo
;;
*)
echo "Invalid Selection."
echo "Select a valid option, press j to Exit or m to show the Menu Options"
;;
esac
done
linux bash
marked as duplicate by JdeBP, Olorin, Kusalananda♦
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();
}
);
});
});
Mar 5 at 9:33
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:
Brackets in if condition: why am I getting syntax errors without whitespace?
3 answers
#!/bin/bash
until ["$userIn" = "j"]
do
echo "Welcome to the Menu_Script Program!"
echo
echo "Menu Options"
echo "Please Select an Option."
echo
echo
echo "Press a to use the Emailer Program"
echo
echo "Press b to Display the Users that are Currently Logged On"
echo
echo "Press c to Display the Current Date and Time"
echo
echo "Press d to Display the Months Calendar"
echo
echo "Press e to Display the name of the Working Directory"
echo
echo "Press f to Display the Contents of the Working Directory"
echo
echo "Press g to Find the IP of a Web Address"
echo
echo "Press h to See your Fortune"
echo
echo "Press i to Display a file on the screen"
echo
echo
echo "Press j to Exit this Menu"
echo
echo "Press m to show the Menu Options again"
echo
read mOption
case "$mOption" in
a|A)
echo "Welcome to the Emailer Program"
echo
echo "Please enter the content of your message and press <ENTER>:"
read $mContent
echo
echo "Please enter the email address of the recipient and press <ENTER>:"
read $mAddress
echo
echo "Is there a file to be attached to this message? Press Y/N:"
read $ATTACH
echo
if ["$ATTACH"="Y"|"y"]
then
echo "Please enter the name of the FILE to be attached:"
read $mAttach
mail -s "$mContent" "$mAddress"<"$mAttach"
echo
echo "Your mail will be sent with the attachment."
echo
else
mail -s "$mContent""$mAddress"
echo
echo "Your mail will be sent without an attachment."
echo
fi
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
b|B)
echo "Here is a list of users that are currently logged on:"
w
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
c|B)
echo "The current date and time:"
date
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
d|D)
echo "Here is the current Months of the calendar:"
cal
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
e|E)
echo "Here is the name of the Working Directory:"
pwd
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
f|F)
echo "Here is the Contents of the Working Directory"
ls
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
g|G)
echo "Please type a Web Address whose IP Address you"
echo "would like to find, then press <ENTER>:"
read $mWeb
echo
echo "Here is the IP Address Information:"
nslookup $mWeb
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
h|H)
echo "Here is your Fortune for today!"
echo
fortune
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
i|I)
echo "Please enter the name of the file that you want to be displayed:"
read $mFile
echo
echo "Here is your file:"
cat $mFile
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
j|J)
echo "Thank you for using the Menu_Script Program!"
userIn = j
echo
;;
m|M)
echo "Menu Options"
echo "Please Select an Option:"
echo
echo
echo "Press a to use the Emailer Program"
echo
echo "Press b to Display the Users that are Currently Logged On"
echo
echo "Press c to Display the Current Date and Time"
echo
echo "Press d to Display the Months Calendar"
echo
echo "Press e to Display the name of the Working Directory"
echo
echo "Press f to Display the Contents of the Working Directory"
echo
echo "Press g to Find the IP of a Web Address"
echo
echo "Press h to See your Fortune"
echo
echo "Press i to Display a file on the screen"
echo
echo
echo "Press j to Exit this Menu"
echo
echo "Press m to show the Menu Options again"
echo
;;
*)
echo "Invalid Selection."
echo "Select a valid option, press j to Exit or m to show the Menu Options"
;;
esac
done
linux bash
marked as duplicate by JdeBP, Olorin, Kusalananda♦
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();
}
);
});
});
Mar 5 at 9:33
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.
line 7 is this " until ["$userIn" = "j"] "
– Ames
Mar 5 at 9:09
1
Your lines are being counted strange: I think the error is for a different file. Editing the wrong file is one of the most common reasons for confusion, when a fix does not work.
– ctrl-alt-delor
Mar 5 at 10:01
add a comment |
This question already has an answer here:
Brackets in if condition: why am I getting syntax errors without whitespace?
3 answers
#!/bin/bash
until ["$userIn" = "j"]
do
echo "Welcome to the Menu_Script Program!"
echo
echo "Menu Options"
echo "Please Select an Option."
echo
echo
echo "Press a to use the Emailer Program"
echo
echo "Press b to Display the Users that are Currently Logged On"
echo
echo "Press c to Display the Current Date and Time"
echo
echo "Press d to Display the Months Calendar"
echo
echo "Press e to Display the name of the Working Directory"
echo
echo "Press f to Display the Contents of the Working Directory"
echo
echo "Press g to Find the IP of a Web Address"
echo
echo "Press h to See your Fortune"
echo
echo "Press i to Display a file on the screen"
echo
echo
echo "Press j to Exit this Menu"
echo
echo "Press m to show the Menu Options again"
echo
read mOption
case "$mOption" in
a|A)
echo "Welcome to the Emailer Program"
echo
echo "Please enter the content of your message and press <ENTER>:"
read $mContent
echo
echo "Please enter the email address of the recipient and press <ENTER>:"
read $mAddress
echo
echo "Is there a file to be attached to this message? Press Y/N:"
read $ATTACH
echo
if ["$ATTACH"="Y"|"y"]
then
echo "Please enter the name of the FILE to be attached:"
read $mAttach
mail -s "$mContent" "$mAddress"<"$mAttach"
echo
echo "Your mail will be sent with the attachment."
echo
else
mail -s "$mContent""$mAddress"
echo
echo "Your mail will be sent without an attachment."
echo
fi
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
b|B)
echo "Here is a list of users that are currently logged on:"
w
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
c|B)
echo "The current date and time:"
date
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
d|D)
echo "Here is the current Months of the calendar:"
cal
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
e|E)
echo "Here is the name of the Working Directory:"
pwd
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
f|F)
echo "Here is the Contents of the Working Directory"
ls
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
g|G)
echo "Please type a Web Address whose IP Address you"
echo "would like to find, then press <ENTER>:"
read $mWeb
echo
echo "Here is the IP Address Information:"
nslookup $mWeb
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
h|H)
echo "Here is your Fortune for today!"
echo
fortune
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
i|I)
echo "Please enter the name of the file that you want to be displayed:"
read $mFile
echo
echo "Here is your file:"
cat $mFile
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
j|J)
echo "Thank you for using the Menu_Script Program!"
userIn = j
echo
;;
m|M)
echo "Menu Options"
echo "Please Select an Option:"
echo
echo
echo "Press a to use the Emailer Program"
echo
echo "Press b to Display the Users that are Currently Logged On"
echo
echo "Press c to Display the Current Date and Time"
echo
echo "Press d to Display the Months Calendar"
echo
echo "Press e to Display the name of the Working Directory"
echo
echo "Press f to Display the Contents of the Working Directory"
echo
echo "Press g to Find the IP of a Web Address"
echo
echo "Press h to See your Fortune"
echo
echo "Press i to Display a file on the screen"
echo
echo
echo "Press j to Exit this Menu"
echo
echo "Press m to show the Menu Options again"
echo
;;
*)
echo "Invalid Selection."
echo "Select a valid option, press j to Exit or m to show the Menu Options"
;;
esac
done
linux bash
This question already has an answer here:
Brackets in if condition: why am I getting syntax errors without whitespace?
3 answers
#!/bin/bash
until ["$userIn" = "j"]
do
echo "Welcome to the Menu_Script Program!"
echo
echo "Menu Options"
echo "Please Select an Option."
echo
echo
echo "Press a to use the Emailer Program"
echo
echo "Press b to Display the Users that are Currently Logged On"
echo
echo "Press c to Display the Current Date and Time"
echo
echo "Press d to Display the Months Calendar"
echo
echo "Press e to Display the name of the Working Directory"
echo
echo "Press f to Display the Contents of the Working Directory"
echo
echo "Press g to Find the IP of a Web Address"
echo
echo "Press h to See your Fortune"
echo
echo "Press i to Display a file on the screen"
echo
echo
echo "Press j to Exit this Menu"
echo
echo "Press m to show the Menu Options again"
echo
read mOption
case "$mOption" in
a|A)
echo "Welcome to the Emailer Program"
echo
echo "Please enter the content of your message and press <ENTER>:"
read $mContent
echo
echo "Please enter the email address of the recipient and press <ENTER>:"
read $mAddress
echo
echo "Is there a file to be attached to this message? Press Y/N:"
read $ATTACH
echo
if ["$ATTACH"="Y"|"y"]
then
echo "Please enter the name of the FILE to be attached:"
read $mAttach
mail -s "$mContent" "$mAddress"<"$mAttach"
echo
echo "Your mail will be sent with the attachment."
echo
else
mail -s "$mContent""$mAddress"
echo
echo "Your mail will be sent without an attachment."
echo
fi
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
b|B)
echo "Here is a list of users that are currently logged on:"
w
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
c|B)
echo "The current date and time:"
date
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
d|D)
echo "Here is the current Months of the calendar:"
cal
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
e|E)
echo "Here is the name of the Working Directory:"
pwd
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
f|F)
echo "Here is the Contents of the Working Directory"
ls
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
g|G)
echo "Please type a Web Address whose IP Address you"
echo "would like to find, then press <ENTER>:"
read $mWeb
echo
echo "Here is the IP Address Information:"
nslookup $mWeb
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
h|H)
echo "Here is your Fortune for today!"
echo
fortune
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
i|I)
echo "Please enter the name of the file that you want to be displayed:"
read $mFile
echo
echo "Here is your file:"
cat $mFile
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
j|J)
echo "Thank you for using the Menu_Script Program!"
userIn = j
echo
;;
m|M)
echo "Menu Options"
echo "Please Select an Option:"
echo
echo
echo "Press a to use the Emailer Program"
echo
echo "Press b to Display the Users that are Currently Logged On"
echo
echo "Press c to Display the Current Date and Time"
echo
echo "Press d to Display the Months Calendar"
echo
echo "Press e to Display the name of the Working Directory"
echo
echo "Press f to Display the Contents of the Working Directory"
echo
echo "Press g to Find the IP of a Web Address"
echo
echo "Press h to See your Fortune"
echo
echo "Press i to Display a file on the screen"
echo
echo
echo "Press j to Exit this Menu"
echo
echo "Press m to show the Menu Options again"
echo
;;
*)
echo "Invalid Selection."
echo "Select a valid option, press j to Exit or m to show the Menu Options"
;;
esac
done
This question already has an answer here:
Brackets in if condition: why am I getting syntax errors without whitespace?
3 answers
linux bash
linux bash
edited Mar 5 at 9:11
Romeo Ninov
6,90432129
6,90432129
asked Mar 5 at 9:08
AmesAmes
1
1
marked as duplicate by JdeBP, Olorin, Kusalananda♦
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();
}
);
});
});
Mar 5 at 9:33
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 JdeBP, Olorin, Kusalananda♦
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();
}
);
});
});
Mar 5 at 9:33
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.
line 7 is this " until ["$userIn" = "j"] "
– Ames
Mar 5 at 9:09
1
Your lines are being counted strange: I think the error is for a different file. Editing the wrong file is one of the most common reasons for confusion, when a fix does not work.
– ctrl-alt-delor
Mar 5 at 10:01
add a comment |
line 7 is this " until ["$userIn" = "j"] "
– Ames
Mar 5 at 9:09
1
Your lines are being counted strange: I think the error is for a different file. Editing the wrong file is one of the most common reasons for confusion, when a fix does not work.
– ctrl-alt-delor
Mar 5 at 10:01
line 7 is this " until ["$userIn" = "j"] "
– Ames
Mar 5 at 9:09
line 7 is this " until ["$userIn" = "j"] "
– Ames
Mar 5 at 9:09
1
1
Your lines are being counted strange: I think the error is for a different file. Editing the wrong file is one of the most common reasons for confusion, when a fix does not work.
– ctrl-alt-delor
Mar 5 at 10:01
Your lines are being counted strange: I think the error is for a different file. Editing the wrong file is one of the most common reasons for confusion, when a fix does not work.
– ctrl-alt-delor
Mar 5 at 10:01
add a comment |
2 Answers
2
active
oldest
votes
[
is a command.
So you have to do like any other command put space after it to handle argument.
Try man [
.
If you type echofoo
in a terminal it won't work except if you have a binary/command explicity named echofoo
, it most likely says the same thing as your error echofoo: command not found.
add a comment |
You need to add space symbol after open bracket and space before close bracket. This line:
if ["$ATTACH"="Y"|"y"]
to become (to work with more than one symbol)
if [[ $ATTACH == [Yy] ]]
The same for
until ["$userIn" = "j"]
to be
until [ "$userIn" = "j" ]
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
[
is a command.
So you have to do like any other command put space after it to handle argument.
Try man [
.
If you type echofoo
in a terminal it won't work except if you have a binary/command explicity named echofoo
, it most likely says the same thing as your error echofoo: command not found.
add a comment |
[
is a command.
So you have to do like any other command put space after it to handle argument.
Try man [
.
If you type echofoo
in a terminal it won't work except if you have a binary/command explicity named echofoo
, it most likely says the same thing as your error echofoo: command not found.
add a comment |
[
is a command.
So you have to do like any other command put space after it to handle argument.
Try man [
.
If you type echofoo
in a terminal it won't work except if you have a binary/command explicity named echofoo
, it most likely says the same thing as your error echofoo: command not found.
[
is a command.
So you have to do like any other command put space after it to handle argument.
Try man [
.
If you type echofoo
in a terminal it won't work except if you have a binary/command explicity named echofoo
, it most likely says the same thing as your error echofoo: command not found.
edited Mar 5 at 9:51
answered Mar 5 at 9:13
KiwyKiwy
6,10353760
6,10353760
add a comment |
add a comment |
You need to add space symbol after open bracket and space before close bracket. This line:
if ["$ATTACH"="Y"|"y"]
to become (to work with more than one symbol)
if [[ $ATTACH == [Yy] ]]
The same for
until ["$userIn" = "j"]
to be
until [ "$userIn" = "j" ]
add a comment |
You need to add space symbol after open bracket and space before close bracket. This line:
if ["$ATTACH"="Y"|"y"]
to become (to work with more than one symbol)
if [[ $ATTACH == [Yy] ]]
The same for
until ["$userIn" = "j"]
to be
until [ "$userIn" = "j" ]
add a comment |
You need to add space symbol after open bracket and space before close bracket. This line:
if ["$ATTACH"="Y"|"y"]
to become (to work with more than one symbol)
if [[ $ATTACH == [Yy] ]]
The same for
until ["$userIn" = "j"]
to be
until [ "$userIn" = "j" ]
You need to add space symbol after open bracket and space before close bracket. This line:
if ["$ATTACH"="Y"|"y"]
to become (to work with more than one symbol)
if [[ $ATTACH == [Yy] ]]
The same for
until ["$userIn" = "j"]
to be
until [ "$userIn" = "j" ]
edited Mar 5 at 9:38
answered Mar 5 at 9:13
Romeo NinovRomeo Ninov
6,90432129
6,90432129
add a comment |
add a comment |
line 7 is this " until ["$userIn" = "j"] "
– Ames
Mar 5 at 9:09
1
Your lines are being counted strange: I think the error is for a different file. Editing the wrong file is one of the most common reasons for confusion, when a fix does not work.
– ctrl-alt-delor
Mar 5 at 10:01