Bash - Breaking while loop with user input [closed]












0















I am total beginer with linux.



I have found that my question might be sloved already, but i cannot transfer answers to my example.



I am trying to make script which is asking user to provide folder name, then creates directory. After that, bash asks does user want to create next folder, if answer is different than yes, while loop should break.



I appreciate any kind of help.
Thank you in advance.
My code: https://pastebin.com/xKNgV9gg



#!/bin/bash
echo 'Welcome in folder generator'
echo '#################################################'
echo '#################################################'

new_directory="yes"

while [ "$new_directory"=="yes" ]
do
echo 'Give me folder name'
read folderName
mkdir $folderName
echo "Would you like to create next folder ?"
read $new_directory
done









share|improve this question















closed as off-topic by Barmar, Tsyvarev, lagom, CozyAzure, Andrei Suvorkov Nov 26 '18 at 8:30


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Tsyvarev, lagom, CozyAzure, Andrei Suvorkov

If this question can be reworded to fit the rules in the help center, please edit the question.












  • 5





    copy your code in shellcheck.net

    – ingroxd
    Nov 25 '18 at 21:04











  • Add spaces around ==.

    – Barmar
    Nov 25 '18 at 21:12











  • Don't put $ before the variable name in read command.

    – Barmar
    Nov 25 '18 at 21:12











  • Quote your variables in case the folder name has spaces.

    – Barmar
    Nov 25 '18 at 21:12











  • Also see How to use Shellcheck, How to debug a bash script? (U&L.SE), How to debug a bash script? (SO), How to debug bash script? (AskU), Debugging Bash scripts, etc.

    – jww
    Nov 25 '18 at 21:54
















0















I am total beginer with linux.



I have found that my question might be sloved already, but i cannot transfer answers to my example.



I am trying to make script which is asking user to provide folder name, then creates directory. After that, bash asks does user want to create next folder, if answer is different than yes, while loop should break.



I appreciate any kind of help.
Thank you in advance.
My code: https://pastebin.com/xKNgV9gg



#!/bin/bash
echo 'Welcome in folder generator'
echo '#################################################'
echo '#################################################'

new_directory="yes"

while [ "$new_directory"=="yes" ]
do
echo 'Give me folder name'
read folderName
mkdir $folderName
echo "Would you like to create next folder ?"
read $new_directory
done









share|improve this question















closed as off-topic by Barmar, Tsyvarev, lagom, CozyAzure, Andrei Suvorkov Nov 26 '18 at 8:30


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Tsyvarev, lagom, CozyAzure, Andrei Suvorkov

If this question can be reworded to fit the rules in the help center, please edit the question.












  • 5





    copy your code in shellcheck.net

    – ingroxd
    Nov 25 '18 at 21:04











  • Add spaces around ==.

    – Barmar
    Nov 25 '18 at 21:12











  • Don't put $ before the variable name in read command.

    – Barmar
    Nov 25 '18 at 21:12











  • Quote your variables in case the folder name has spaces.

    – Barmar
    Nov 25 '18 at 21:12











  • Also see How to use Shellcheck, How to debug a bash script? (U&L.SE), How to debug a bash script? (SO), How to debug bash script? (AskU), Debugging Bash scripts, etc.

    – jww
    Nov 25 '18 at 21:54














0












0








0








I am total beginer with linux.



I have found that my question might be sloved already, but i cannot transfer answers to my example.



I am trying to make script which is asking user to provide folder name, then creates directory. After that, bash asks does user want to create next folder, if answer is different than yes, while loop should break.



I appreciate any kind of help.
Thank you in advance.
My code: https://pastebin.com/xKNgV9gg



#!/bin/bash
echo 'Welcome in folder generator'
echo '#################################################'
echo '#################################################'

new_directory="yes"

while [ "$new_directory"=="yes" ]
do
echo 'Give me folder name'
read folderName
mkdir $folderName
echo "Would you like to create next folder ?"
read $new_directory
done









share|improve this question
















I am total beginer with linux.



I have found that my question might be sloved already, but i cannot transfer answers to my example.



I am trying to make script which is asking user to provide folder name, then creates directory. After that, bash asks does user want to create next folder, if answer is different than yes, while loop should break.



I appreciate any kind of help.
Thank you in advance.
My code: https://pastebin.com/xKNgV9gg



#!/bin/bash
echo 'Welcome in folder generator'
echo '#################################################'
echo '#################################################'

new_directory="yes"

while [ "$new_directory"=="yes" ]
do
echo 'Give me folder name'
read folderName
mkdir $folderName
echo "Would you like to create next folder ?"
read $new_directory
done






linux bash






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 21:03









George Vasiliou

4,20221018




4,20221018










asked Nov 25 '18 at 20:59









Przemysław PorębskiPrzemysław Porębski

32




32




closed as off-topic by Barmar, Tsyvarev, lagom, CozyAzure, Andrei Suvorkov Nov 26 '18 at 8:30


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Tsyvarev, lagom, CozyAzure, Andrei Suvorkov

If this question can be reworded to fit the rules in the help center, please edit the question.







closed as off-topic by Barmar, Tsyvarev, lagom, CozyAzure, Andrei Suvorkov Nov 26 '18 at 8:30


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Tsyvarev, lagom, CozyAzure, Andrei Suvorkov

If this question can be reworded to fit the rules in the help center, please edit the question.








  • 5





    copy your code in shellcheck.net

    – ingroxd
    Nov 25 '18 at 21:04











  • Add spaces around ==.

    – Barmar
    Nov 25 '18 at 21:12











  • Don't put $ before the variable name in read command.

    – Barmar
    Nov 25 '18 at 21:12











  • Quote your variables in case the folder name has spaces.

    – Barmar
    Nov 25 '18 at 21:12











  • Also see How to use Shellcheck, How to debug a bash script? (U&L.SE), How to debug a bash script? (SO), How to debug bash script? (AskU), Debugging Bash scripts, etc.

    – jww
    Nov 25 '18 at 21:54














  • 5





    copy your code in shellcheck.net

    – ingroxd
    Nov 25 '18 at 21:04











  • Add spaces around ==.

    – Barmar
    Nov 25 '18 at 21:12











  • Don't put $ before the variable name in read command.

    – Barmar
    Nov 25 '18 at 21:12











  • Quote your variables in case the folder name has spaces.

    – Barmar
    Nov 25 '18 at 21:12











  • Also see How to use Shellcheck, How to debug a bash script? (U&L.SE), How to debug a bash script? (SO), How to debug bash script? (AskU), Debugging Bash scripts, etc.

    – jww
    Nov 25 '18 at 21:54








5




5





copy your code in shellcheck.net

– ingroxd
Nov 25 '18 at 21:04





copy your code in shellcheck.net

– ingroxd
Nov 25 '18 at 21:04













Add spaces around ==.

– Barmar
Nov 25 '18 at 21:12





Add spaces around ==.

– Barmar
Nov 25 '18 at 21:12













Don't put $ before the variable name in read command.

– Barmar
Nov 25 '18 at 21:12





Don't put $ before the variable name in read command.

– Barmar
Nov 25 '18 at 21:12













Quote your variables in case the folder name has spaces.

– Barmar
Nov 25 '18 at 21:12





Quote your variables in case the folder name has spaces.

– Barmar
Nov 25 '18 at 21:12













Also see How to use Shellcheck, How to debug a bash script? (U&L.SE), How to debug a bash script? (SO), How to debug bash script? (AskU), Debugging Bash scripts, etc.

– jww
Nov 25 '18 at 21:54





Also see How to use Shellcheck, How to debug a bash script? (U&L.SE), How to debug a bash script? (SO), How to debug bash script? (AskU), Debugging Bash scripts, etc.

– jww
Nov 25 '18 at 21:54












1 Answer
1






active

oldest

votes


















-1















  1. Bash is whitespace (spaces, tabs, newlines) separated.


  2. [ a = b ] is not equal to [ a=b ]. The first compares string 'a' with string 'b', the second check if the string 'a=b' has non-zero length.

  3. Always quote your variables, unless you know you don't have to.

  4. Bash uses single = for string comparision. Double == is supported, but is not standard.

  5. A good read can be found in this thread.




#!/bin/bash
echo 'Welcome in folder generator'
echo '#################################################'
echo '#################################################'

new_directory="yes"

while [ "$new_directory" == "yes" ]
do
echo 'Give me folder name'
read folderName
mkdir "$folderName"
echo "Would you like to create next folder ?"
read new_directory
done





share|improve this answer





















  • 2





    It still has errors and will not work as intended. Line 14 is buggy. Is all explained in shellcheck.net

    – George Vasiliou
    Nov 25 '18 at 21:29




















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









-1















  1. Bash is whitespace (spaces, tabs, newlines) separated.


  2. [ a = b ] is not equal to [ a=b ]. The first compares string 'a' with string 'b', the second check if the string 'a=b' has non-zero length.

  3. Always quote your variables, unless you know you don't have to.

  4. Bash uses single = for string comparision. Double == is supported, but is not standard.

  5. A good read can be found in this thread.




#!/bin/bash
echo 'Welcome in folder generator'
echo '#################################################'
echo '#################################################'

new_directory="yes"

while [ "$new_directory" == "yes" ]
do
echo 'Give me folder name'
read folderName
mkdir "$folderName"
echo "Would you like to create next folder ?"
read new_directory
done





share|improve this answer





















  • 2





    It still has errors and will not work as intended. Line 14 is buggy. Is all explained in shellcheck.net

    – George Vasiliou
    Nov 25 '18 at 21:29


















-1















  1. Bash is whitespace (spaces, tabs, newlines) separated.


  2. [ a = b ] is not equal to [ a=b ]. The first compares string 'a' with string 'b', the second check if the string 'a=b' has non-zero length.

  3. Always quote your variables, unless you know you don't have to.

  4. Bash uses single = for string comparision. Double == is supported, but is not standard.

  5. A good read can be found in this thread.




#!/bin/bash
echo 'Welcome in folder generator'
echo '#################################################'
echo '#################################################'

new_directory="yes"

while [ "$new_directory" == "yes" ]
do
echo 'Give me folder name'
read folderName
mkdir "$folderName"
echo "Would you like to create next folder ?"
read new_directory
done





share|improve this answer





















  • 2





    It still has errors and will not work as intended. Line 14 is buggy. Is all explained in shellcheck.net

    – George Vasiliou
    Nov 25 '18 at 21:29
















-1












-1








-1








  1. Bash is whitespace (spaces, tabs, newlines) separated.


  2. [ a = b ] is not equal to [ a=b ]. The first compares string 'a' with string 'b', the second check if the string 'a=b' has non-zero length.

  3. Always quote your variables, unless you know you don't have to.

  4. Bash uses single = for string comparision. Double == is supported, but is not standard.

  5. A good read can be found in this thread.




#!/bin/bash
echo 'Welcome in folder generator'
echo '#################################################'
echo '#################################################'

new_directory="yes"

while [ "$new_directory" == "yes" ]
do
echo 'Give me folder name'
read folderName
mkdir "$folderName"
echo "Would you like to create next folder ?"
read new_directory
done





share|improve this answer
















  1. Bash is whitespace (spaces, tabs, newlines) separated.


  2. [ a = b ] is not equal to [ a=b ]. The first compares string 'a' with string 'b', the second check if the string 'a=b' has non-zero length.

  3. Always quote your variables, unless you know you don't have to.

  4. Bash uses single = for string comparision. Double == is supported, but is not standard.

  5. A good read can be found in this thread.




#!/bin/bash
echo 'Welcome in folder generator'
echo '#################################################'
echo '#################################################'

new_directory="yes"

while [ "$new_directory" == "yes" ]
do
echo 'Give me folder name'
read folderName
mkdir "$folderName"
echo "Would you like to create next folder ?"
read new_directory
done






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 25 '18 at 21:47

























answered Nov 25 '18 at 21:21









Kamil CukKamil Cuk

11.8k1529




11.8k1529








  • 2





    It still has errors and will not work as intended. Line 14 is buggy. Is all explained in shellcheck.net

    – George Vasiliou
    Nov 25 '18 at 21:29
















  • 2





    It still has errors and will not work as intended. Line 14 is buggy. Is all explained in shellcheck.net

    – George Vasiliou
    Nov 25 '18 at 21:29










2




2





It still has errors and will not work as intended. Line 14 is buggy. Is all explained in shellcheck.net

– George Vasiliou
Nov 25 '18 at 21:29







It still has errors and will not work as intended. Line 14 is buggy. Is all explained in shellcheck.net

– George Vasiliou
Nov 25 '18 at 21:29







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'