0

So I need my while loop to continually loop but it stops after the first user's input, example:

[user]$: ./pleasefix.sh

Enter Input:test

test is writeable.

[user]$:

Heres my script as it is:

if [ "$#" -ne 0 ]
   then
        echo  "$0" "is expecting no arguments; found $# $*"
        echo "Usage: "$0""
        exit 2
fi

while read -p "Enter Input:" userString
do

if [ -w "$userString" ]
   then
        echo ""$userString" is writeable."
        exit 0
   else
        echo ""$userString" is nonexistent or not writeable."

        exit 1

fi
done

What can I add to my while to make it actually loop and re prompt the user for another file name? Basically I want it to last forever until a EOF is sent (crtl + D)

2
  • 1
    You exit call exits the script Commented Feb 28, 2013 at 23:08
  • echo ""$userString" is writeable." is very unusual quoting style. Either echo "$userString is writeable." or echo $userString is writeable. would be far more typical. Commented Feb 28, 2013 at 23:39

3 Answers 3

2

Take the exit 0 and exit 1 out

Sign up to request clarification or add additional context in comments.

Comments

1

You are using "exit" at both case if-else. You can remove one of them.

1 Comment

I have to give enough contribution to the group in order to get a privilege to ask question again.So you can upvote. thanks :)
0

Remove the "exit 0" and the "exit 1"? Those will cause it to exit your script.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.