How to loop with case esac in shell scripting?Resize multiple files and rename them properlyCase sensitivity in shell scriptingRun multiple line as a single line command bashbash: populating array with elements containing spaces and special charactersProblem with input from simple script that copies a file to a different directoryUsing user input to determine how many times a for loop iteratesline 42: syntax error: unexpected end of fileInstalling Ruby On Rails shows errors on line 168Create bash script that allows you to choose multiple options instead of just one?Write a regular expression which catches user $HOME in shellscripting
What is the meaning of "of trouble" in the following sentence?
What do you call a Matrix-like slowdown and camera movement effect?
Why is "Reports" in sentence down without "The"
How does one intimidate enemies without having the capacity for violence?
Why did the Germans forbid the possession of pet pigeons in Rostov-on-Don in 1941?
Why was the small council so happy for Tyrion to become the Master of Coin?
"which" command doesn't work / path of Safari?
Infinite past with a beginning?
How to report a triplet of septets in NMR tabulation?
A Journey Through Space and Time
The use of multiple foreign keys on same column in SQL Server
DOS, create pipe for stdin/stdout of command.com(or 4dos.com) in C or Batch?
Is there a familial term for apples and pears?
Example of a relative pronoun
How do we improve the relationship with a client software team that performs poorly and is becoming less collaborative?
Simulate Bitwise Cyclic Tag
Is it tax fraud for an individual to declare non-taxable revenue as taxable income? (US tax laws)
Chess with symmetric move-square
least quadratic residue under GRH: an EXPLICIT bound
Why is an old chain unsafe?
Modification to Chariots for Heavy Cavalry Analogue for 4-armed race
What makes Graph invariants so useful/important?
Are white and non-white police officers equally likely to kill black suspects?
Is there really no realistic way for a skeleton monster to move around without magic?
How to loop with case esac in shell scripting?
Resize multiple files and rename them properlyCase sensitivity in shell scriptingRun multiple line as a single line command bashbash: populating array with elements containing spaces and special charactersProblem with input from simple script that copies a file to a different directoryUsing user input to determine how many times a for loop iteratesline 42: syntax error: unexpected end of fileInstalling Ruby On Rails shows errors on line 168Create bash script that allows you to choose multiple options instead of just one?Write a regular expression which catches user $HOME in shellscripting
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'd like to write a script where if a user enters a path which contains his/her $HOME
directory, it would raise an error and the script will run until user enters a valid path in which the loop will break.
Apparently it gives a syntax error if I have continue
or break
commands. What do I do wrong here? Thanks, Jen.
#!/bin/bash
function project1_install_dir_path()
boolian_2=true;
while true; do
if [ "$boolian_2" = true ] ; then
read -p "Enter FULL folder path where you want to install colsim1:" fullpath
echo "you have enterd "$fullpath". Please press 'y' to confirm and 'n' to enter again"
case "$fullpath" in
"$HOME"*) echo "Error: The path cannot be in your HOME" ;; continue
*/home*) echo "Error: The path cannot contain 'home' in the path" ;; continue
*) echo "you have entered a valid path" ;; break
esac
done
fi
function main()
project1_install_dir_path
Terminal Output
jen@ss23:/bash_file.sh
-bash: /project/bash_file.sh: line 62: syntax error near unexpected token `newline'
-bash: /project/bash_file.sh: line 62: ` "$HOME"*) echo "Error: The path cannot be in your HOME" ;; continue
command-line bash scripts
add a comment |
I'd like to write a script where if a user enters a path which contains his/her $HOME
directory, it would raise an error and the script will run until user enters a valid path in which the loop will break.
Apparently it gives a syntax error if I have continue
or break
commands. What do I do wrong here? Thanks, Jen.
#!/bin/bash
function project1_install_dir_path()
boolian_2=true;
while true; do
if [ "$boolian_2" = true ] ; then
read -p "Enter FULL folder path where you want to install colsim1:" fullpath
echo "you have enterd "$fullpath". Please press 'y' to confirm and 'n' to enter again"
case "$fullpath" in
"$HOME"*) echo "Error: The path cannot be in your HOME" ;; continue
*/home*) echo "Error: The path cannot contain 'home' in the path" ;; continue
*) echo "you have entered a valid path" ;; break
esac
done
fi
function main()
project1_install_dir_path
Terminal Output
jen@ss23:/bash_file.sh
-bash: /project/bash_file.sh: line 62: syntax error near unexpected token `newline'
-bash: /project/bash_file.sh: line 62: ` "$HOME"*) echo "Error: The path cannot be in your HOME" ;; continue
command-line bash scripts
3
The;;
at the end of the case mark the end. Thus, your followingbreak
orcontinue
commands are ignored.*) echo "you have entered a valid path" ; break ;;
is more like what you need.
– waltinator
2 days ago
add a comment |
I'd like to write a script where if a user enters a path which contains his/her $HOME
directory, it would raise an error and the script will run until user enters a valid path in which the loop will break.
Apparently it gives a syntax error if I have continue
or break
commands. What do I do wrong here? Thanks, Jen.
#!/bin/bash
function project1_install_dir_path()
boolian_2=true;
while true; do
if [ "$boolian_2" = true ] ; then
read -p "Enter FULL folder path where you want to install colsim1:" fullpath
echo "you have enterd "$fullpath". Please press 'y' to confirm and 'n' to enter again"
case "$fullpath" in
"$HOME"*) echo "Error: The path cannot be in your HOME" ;; continue
*/home*) echo "Error: The path cannot contain 'home' in the path" ;; continue
*) echo "you have entered a valid path" ;; break
esac
done
fi
function main()
project1_install_dir_path
Terminal Output
jen@ss23:/bash_file.sh
-bash: /project/bash_file.sh: line 62: syntax error near unexpected token `newline'
-bash: /project/bash_file.sh: line 62: ` "$HOME"*) echo "Error: The path cannot be in your HOME" ;; continue
command-line bash scripts
I'd like to write a script where if a user enters a path which contains his/her $HOME
directory, it would raise an error and the script will run until user enters a valid path in which the loop will break.
Apparently it gives a syntax error if I have continue
or break
commands. What do I do wrong here? Thanks, Jen.
#!/bin/bash
function project1_install_dir_path()
boolian_2=true;
while true; do
if [ "$boolian_2" = true ] ; then
read -p "Enter FULL folder path where you want to install colsim1:" fullpath
echo "you have enterd "$fullpath". Please press 'y' to confirm and 'n' to enter again"
case "$fullpath" in
"$HOME"*) echo "Error: The path cannot be in your HOME" ;; continue
*/home*) echo "Error: The path cannot contain 'home' in the path" ;; continue
*) echo "you have entered a valid path" ;; break
esac
done
fi
function main()
project1_install_dir_path
Terminal Output
jen@ss23:/bash_file.sh
-bash: /project/bash_file.sh: line 62: syntax error near unexpected token `newline'
-bash: /project/bash_file.sh: line 62: ` "$HOME"*) echo "Error: The path cannot be in your HOME" ;; continue
command-line bash scripts
command-line bash scripts
asked 2 days ago
JennyJenny
968
968
3
The;;
at the end of the case mark the end. Thus, your followingbreak
orcontinue
commands are ignored.*) echo "you have entered a valid path" ; break ;;
is more like what you need.
– waltinator
2 days ago
add a comment |
3
The;;
at the end of the case mark the end. Thus, your followingbreak
orcontinue
commands are ignored.*) echo "you have entered a valid path" ; break ;;
is more like what you need.
– waltinator
2 days ago
3
3
The
;;
at the end of the case mark the end. Thus, your following break
or continue
commands are ignored. *) echo "you have entered a valid path" ; break ;;
is more like what you need.– waltinator
2 days ago
The
;;
at the end of the case mark the end. Thus, your following break
or continue
commands are ignored. *) echo "you have entered a valid path" ; break ;;
is more like what you need.– waltinator
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
You should really check your indentation. The final done
and fi
statements are in the wrong order although your indentation suggests otherwise. Another issue is the case
statement. The basic syntax is
case $SOMETHING in
value1)
statement1;
statement2;
;;
value2)
statement3;
statement4;
;;
esac
That is: the final ;;
must actually be the last statement for each case and indicates its end. If you want to continue
in some case, then you need to put that continue
statement before any ;;
, like so:
#!/bin/bash
function project1_install_dir_path()
boolian_2=true;
while true; do
if [ "$boolian_2" = true ] ; then
read -p "Enter FULL folder path where you want to install colsim1:" fullpath
echo "you have enterd '$fullpath'. Please press 'y' to confirm and 'n' to enter again"
case "$fullpath" in
"$HOME"*)
echo "Error: The path cannot be in your HOME";
continue;
;;
*/home*)
echo "Error: The path cannot contain 'home' in the path";
continue;
;;
*)
echo "you have entered a valid path";
break;
;;
esac
fi
done
function main()
project1_install_dir_path
main;
2
Just a note, trailing;
is not necessary if you're using newline to separate commands. If two commands are on the same line, then you do want to use semicolon, as inecho foo ; echo bar
– Sergiy Kolodyazhnyy
2 days ago
@SergiyKolodyazhnyy Exactly. It's just a habit of mine because some other languages (Perl, for example) need it. Python, as another example, does not need it and in fact warns you about deprecated or old-fashioned style if you put;
after a statement. Please feel invited to remove the unnecessary;
from this post.
– PerlDuck
2 days ago
2
Three general remarks: You are not really using boolian_2, your are asking textually for a confirmation which is not asked for, and finally there are other strings defining a path in my home that would pass your tests (like ~/mydir, or /*/myusername, ...).
– muclux
2 days ago
Indeed, @muclux. I just fixed the syntax, not the semantics of the original script.
– PerlDuck
11 hours ago
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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
);
);
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%2faskubuntu.com%2fquestions%2f1131468%2fhow-to-loop-with-case-esac-in-shell-scripting%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You should really check your indentation. The final done
and fi
statements are in the wrong order although your indentation suggests otherwise. Another issue is the case
statement. The basic syntax is
case $SOMETHING in
value1)
statement1;
statement2;
;;
value2)
statement3;
statement4;
;;
esac
That is: the final ;;
must actually be the last statement for each case and indicates its end. If you want to continue
in some case, then you need to put that continue
statement before any ;;
, like so:
#!/bin/bash
function project1_install_dir_path()
boolian_2=true;
while true; do
if [ "$boolian_2" = true ] ; then
read -p "Enter FULL folder path where you want to install colsim1:" fullpath
echo "you have enterd '$fullpath'. Please press 'y' to confirm and 'n' to enter again"
case "$fullpath" in
"$HOME"*)
echo "Error: The path cannot be in your HOME";
continue;
;;
*/home*)
echo "Error: The path cannot contain 'home' in the path";
continue;
;;
*)
echo "you have entered a valid path";
break;
;;
esac
fi
done
function main()
project1_install_dir_path
main;
2
Just a note, trailing;
is not necessary if you're using newline to separate commands. If two commands are on the same line, then you do want to use semicolon, as inecho foo ; echo bar
– Sergiy Kolodyazhnyy
2 days ago
@SergiyKolodyazhnyy Exactly. It's just a habit of mine because some other languages (Perl, for example) need it. Python, as another example, does not need it and in fact warns you about deprecated or old-fashioned style if you put;
after a statement. Please feel invited to remove the unnecessary;
from this post.
– PerlDuck
2 days ago
2
Three general remarks: You are not really using boolian_2, your are asking textually for a confirmation which is not asked for, and finally there are other strings defining a path in my home that would pass your tests (like ~/mydir, or /*/myusername, ...).
– muclux
2 days ago
Indeed, @muclux. I just fixed the syntax, not the semantics of the original script.
– PerlDuck
11 hours ago
add a comment |
You should really check your indentation. The final done
and fi
statements are in the wrong order although your indentation suggests otherwise. Another issue is the case
statement. The basic syntax is
case $SOMETHING in
value1)
statement1;
statement2;
;;
value2)
statement3;
statement4;
;;
esac
That is: the final ;;
must actually be the last statement for each case and indicates its end. If you want to continue
in some case, then you need to put that continue
statement before any ;;
, like so:
#!/bin/bash
function project1_install_dir_path()
boolian_2=true;
while true; do
if [ "$boolian_2" = true ] ; then
read -p "Enter FULL folder path where you want to install colsim1:" fullpath
echo "you have enterd '$fullpath'. Please press 'y' to confirm and 'n' to enter again"
case "$fullpath" in
"$HOME"*)
echo "Error: The path cannot be in your HOME";
continue;
;;
*/home*)
echo "Error: The path cannot contain 'home' in the path";
continue;
;;
*)
echo "you have entered a valid path";
break;
;;
esac
fi
done
function main()
project1_install_dir_path
main;
2
Just a note, trailing;
is not necessary if you're using newline to separate commands. If two commands are on the same line, then you do want to use semicolon, as inecho foo ; echo bar
– Sergiy Kolodyazhnyy
2 days ago
@SergiyKolodyazhnyy Exactly. It's just a habit of mine because some other languages (Perl, for example) need it. Python, as another example, does not need it and in fact warns you about deprecated or old-fashioned style if you put;
after a statement. Please feel invited to remove the unnecessary;
from this post.
– PerlDuck
2 days ago
2
Three general remarks: You are not really using boolian_2, your are asking textually for a confirmation which is not asked for, and finally there are other strings defining a path in my home that would pass your tests (like ~/mydir, or /*/myusername, ...).
– muclux
2 days ago
Indeed, @muclux. I just fixed the syntax, not the semantics of the original script.
– PerlDuck
11 hours ago
add a comment |
You should really check your indentation. The final done
and fi
statements are in the wrong order although your indentation suggests otherwise. Another issue is the case
statement. The basic syntax is
case $SOMETHING in
value1)
statement1;
statement2;
;;
value2)
statement3;
statement4;
;;
esac
That is: the final ;;
must actually be the last statement for each case and indicates its end. If you want to continue
in some case, then you need to put that continue
statement before any ;;
, like so:
#!/bin/bash
function project1_install_dir_path()
boolian_2=true;
while true; do
if [ "$boolian_2" = true ] ; then
read -p "Enter FULL folder path where you want to install colsim1:" fullpath
echo "you have enterd '$fullpath'. Please press 'y' to confirm and 'n' to enter again"
case "$fullpath" in
"$HOME"*)
echo "Error: The path cannot be in your HOME";
continue;
;;
*/home*)
echo "Error: The path cannot contain 'home' in the path";
continue;
;;
*)
echo "you have entered a valid path";
break;
;;
esac
fi
done
function main()
project1_install_dir_path
main;
You should really check your indentation. The final done
and fi
statements are in the wrong order although your indentation suggests otherwise. Another issue is the case
statement. The basic syntax is
case $SOMETHING in
value1)
statement1;
statement2;
;;
value2)
statement3;
statement4;
;;
esac
That is: the final ;;
must actually be the last statement for each case and indicates its end. If you want to continue
in some case, then you need to put that continue
statement before any ;;
, like so:
#!/bin/bash
function project1_install_dir_path()
boolian_2=true;
while true; do
if [ "$boolian_2" = true ] ; then
read -p "Enter FULL folder path where you want to install colsim1:" fullpath
echo "you have enterd '$fullpath'. Please press 'y' to confirm and 'n' to enter again"
case "$fullpath" in
"$HOME"*)
echo "Error: The path cannot be in your HOME";
continue;
;;
*/home*)
echo "Error: The path cannot contain 'home' in the path";
continue;
;;
*)
echo "you have entered a valid path";
break;
;;
esac
fi
done
function main()
project1_install_dir_path
main;
answered 2 days ago
PerlDuckPerlDuck
8,00611636
8,00611636
2
Just a note, trailing;
is not necessary if you're using newline to separate commands. If two commands are on the same line, then you do want to use semicolon, as inecho foo ; echo bar
– Sergiy Kolodyazhnyy
2 days ago
@SergiyKolodyazhnyy Exactly. It's just a habit of mine because some other languages (Perl, for example) need it. Python, as another example, does not need it and in fact warns you about deprecated or old-fashioned style if you put;
after a statement. Please feel invited to remove the unnecessary;
from this post.
– PerlDuck
2 days ago
2
Three general remarks: You are not really using boolian_2, your are asking textually for a confirmation which is not asked for, and finally there are other strings defining a path in my home that would pass your tests (like ~/mydir, or /*/myusername, ...).
– muclux
2 days ago
Indeed, @muclux. I just fixed the syntax, not the semantics of the original script.
– PerlDuck
11 hours ago
add a comment |
2
Just a note, trailing;
is not necessary if you're using newline to separate commands. If two commands are on the same line, then you do want to use semicolon, as inecho foo ; echo bar
– Sergiy Kolodyazhnyy
2 days ago
@SergiyKolodyazhnyy Exactly. It's just a habit of mine because some other languages (Perl, for example) need it. Python, as another example, does not need it and in fact warns you about deprecated or old-fashioned style if you put;
after a statement. Please feel invited to remove the unnecessary;
from this post.
– PerlDuck
2 days ago
2
Three general remarks: You are not really using boolian_2, your are asking textually for a confirmation which is not asked for, and finally there are other strings defining a path in my home that would pass your tests (like ~/mydir, or /*/myusername, ...).
– muclux
2 days ago
Indeed, @muclux. I just fixed the syntax, not the semantics of the original script.
– PerlDuck
11 hours ago
2
2
Just a note, trailing
;
is not necessary if you're using newline to separate commands. If two commands are on the same line, then you do want to use semicolon, as in echo foo ; echo bar
– Sergiy Kolodyazhnyy
2 days ago
Just a note, trailing
;
is not necessary if you're using newline to separate commands. If two commands are on the same line, then you do want to use semicolon, as in echo foo ; echo bar
– Sergiy Kolodyazhnyy
2 days ago
@SergiyKolodyazhnyy Exactly. It's just a habit of mine because some other languages (Perl, for example) need it. Python, as another example, does not need it and in fact warns you about deprecated or old-fashioned style if you put
;
after a statement. Please feel invited to remove the unnecessary ;
from this post.– PerlDuck
2 days ago
@SergiyKolodyazhnyy Exactly. It's just a habit of mine because some other languages (Perl, for example) need it. Python, as another example, does not need it and in fact warns you about deprecated or old-fashioned style if you put
;
after a statement. Please feel invited to remove the unnecessary ;
from this post.– PerlDuck
2 days ago
2
2
Three general remarks: You are not really using boolian_2, your are asking textually for a confirmation which is not asked for, and finally there are other strings defining a path in my home that would pass your tests (like ~/mydir, or /*/myusername, ...).
– muclux
2 days ago
Three general remarks: You are not really using boolian_2, your are asking textually for a confirmation which is not asked for, and finally there are other strings defining a path in my home that would pass your tests (like ~/mydir, or /*/myusername, ...).
– muclux
2 days ago
Indeed, @muclux. I just fixed the syntax, not the semantics of the original script.
– PerlDuck
11 hours ago
Indeed, @muclux. I just fixed the syntax, not the semantics of the original script.
– PerlDuck
11 hours ago
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- 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%2faskubuntu.com%2fquestions%2f1131468%2fhow-to-loop-with-case-esac-in-shell-scripting%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
3
The
;;
at the end of the case mark the end. Thus, your followingbreak
orcontinue
commands are ignored.*) echo "you have entered a valid path" ; break ;;
is more like what you need.– waltinator
2 days ago