Title: Bash script exiting when repeated in double click execution
Tags: command-line;bash;scripts
Question: This is my code

```#!/bin/bash
function boo {

    function goo {
        echo "Please enter name"
            read name;
        echo "Hello $name"

    }

    function xoo {

        echo "Please enter number"
        read numl;
        echo "$numl"
    }

    read -p "`echo $'\n&gt; \n&gt;'`  Name N or Number S`echo $'\n&gt; \n&gt;'`" var
        if [[ $var =~ [nN](es)* ]]
            then    
                goo   
                elif [[ $var =~ [sS](es)* ]]
                then
                xoo
                fi

}
boo
read -p "`echo $'\n&gt; \n&gt;'`  To Repeat press Y`echo $'\n&gt; \n&gt;'`" prompt
if [[ $prompt =~ [yY](es)* ]]
then
boo    
else
echo""
fi
```

Initially I am able to successfully run this script by double clicking but when I tried to repeat it its exiting

```&gt; 
&gt;  Name N or Number S
&gt; 
&gt;n
Please enter name
john
Hello john

&gt; 
&gt;  To Repeat press Y
&gt; 
&gt;y

&gt; 
&gt;  Name N or Number S
&gt; 
&gt;n
Please enter name
ajay
```

I am able to print hello john but when i enter ajay its exiting. Any idea whats happening


Here is the accepted answer: Your problem is the ```if…then```. After the first call off ```boo``` you check the value of ```prompt``` and ```boo``` will be started, if ```prompt``` is ```y```. After that, there is no more code to execute and the script exits.

Using this script

```#!/bin/bash
function boo {
    function goo {
        echo "Please enter name"
        read -r name;
        echo "Hello $name"
    }

    function xoo {
        echo "Please enter number"
        read -r numl;
        echo "$numl"
    }

    read -rep $'\n&gt; \n&gt; Name N or Number S \n&gt; \n&gt; ' var
    if [[ $var =~ [nN](es)* ]]; then    
      goo   
    elif [[ $var =~ [sS](es)* ]]; then
      xoo
    fi
}

while true; do
  boo
  read -rep $'\n&gt; \n&gt; To Repeat press Y \n&gt; \n&gt; ' prompt
  if [[ ! $prompt =~ [yY](es)* ]]; then
    break
  fi
done

exit 0
```



Example

```% ./foo

&gt; 
&gt; Name N or Number S 
&gt; 
&gt; N
Please enter name
abc
Hello abc

&gt; 
&gt; To Repeat press Y 
&gt; 
&gt; y

&gt; 
&gt; Name N or Number S 
&gt; 
&gt; N
Please enter name
def
Hello def

&gt; 
&gt; To Repeat press Y 
&gt; 
&gt; y

&gt; 
&gt; Name N or Number S 
&gt; 
&gt; N
Please enter name
jjj
Hello jjj

&gt; 
&gt; To Repeat press Y 
&gt; 
&gt; n
%
```

Comment for this answer: Thanks it worked but can you tell me where i made the mistake. why **read -r** , **read -rep** and while loop


{'source': 'StackExchangeDataset', 'subset': 'askubuntu.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2015:00:07/29/15', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<command-line><bash><scripts>', 'Title': 'Bash script exiting when repeated in double click execution', 'ViewCount': 139, 'id': 653977, 'user_AboutMe': '', 'user_AccountId': 6370286.0, 'user_DisplayName': 'potholiday', 'user_Reputation': 585.0, 'user_Views': 66.0, 'user_id': 414116.0}}