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;








1















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









share|improve this question

















  • 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

















1















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









share|improve this question

















  • 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













1












1








1








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









share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 2 days ago









JennyJenny

968




968







  • 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












  • 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







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










1 Answer
1






active

oldest

votes


















2














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;





share|improve this answer


















  • 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











  • @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











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
);



);













draft saved

draft discarded


















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









2














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;





share|improve this answer


















  • 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











  • @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














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;





share|improve this answer


















  • 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











  • @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








2







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;





share|improve this answer













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;






share|improve this answer












share|improve this answer



share|improve this answer










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 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






  • 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





    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






  • 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

















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Tamil (spriik) Luke uk diar | Nawigatjuun

Align equal signs while including text over equalitiesAMS align: left aligned text/math plus multicolumn alignmentMultiple alignmentsAligning equations in multiple placesNumbering and aligning an equation with multiple columnsHow to align one equation with another multline equationUsing \ in environments inside the begintabularxNumber equations and preserving alignment of equal signsHow can I align equations to the left and to the right?Double equation alignment problem within align enviromentAligned within align: Why are they right-aligned?

Where does the image of a data connector as a sharp metal spike originate from?Where does the concept of infected people turning into zombies only after death originate from?Where does the motif of a reanimated human head originate?Where did the notion that Dragons could speak originate?Where does the archetypal image of the 'Grey' alien come from?Where did the suffix '-Man' originate?Where does the notion of being injured or killed by an illusion originate?Where did the term “sophont” originate?Where does the trope of magic spells being driven by advanced technology originate from?Where did the term “the living impaired” originate?