Find the answer to your Linux question:
Results 1 to 2 of 2
I've been trying to this script out for most of the day, and i've looked at several toutorials and I can't figure out why this isn't working. I run into ...
  1. #1
    Just Joined!
    Join Date
    Oct 2008
    Posts
    4

    Simple Scripting Woes

    I've been trying to this script out for most of the day, and i've looked at several toutorials and I can't figure out why this isn't working.

    I run into a loop when the script starts, it always tries to rm file no matter what I input into the shell. and i've tried read
    Code:
    -p': ' ANSWER
    as well.
    Code:
    #!/bin/bash -x
    while [ -f /$HOME/file ]; do
    	echo "File exists rm?: y or n";	read  ANSWER
    		if [ $ANSWER = "y" ]
    		then
    		rm -r /$HOME/file
    		echo "File removed"
    		elif [ $ANSWER = "q"]
    		then
    		echo "Script exiting"
    		exit 0
    		else 
    		echo "File exists, script terminating"
    
    	fi
    done
    if [ !-f /$HOME/file ]
    	then "File does not exist. Do you wish to create it? :y or n"
    	read -p': '  ANSWER2
    		if [  "$ANSWER2" = "y" ]
    		then 
    		touch file
    		echo $ANSWER2 "File created, script terminated"
    		else
    		echo $ANSWER2 "File not created, script terminated"
    	fi
    fi

  2. #2
    Just Joined!
    Join Date
    Oct 2008
    Posts
    4
    Quote Originally Posted by Hrontore View Post
    I've been trying to this script out for most of the day, and i've looked at several toutorials and I can't figure out why this isn't working.

    I run into a loop when the script starts, it always tries to rm file no matter what I input into the shell. and i've tried read
    Code:
    -p': ' ANSWER
    as well.
    Code:
    #!/bin/bash -x
    while [ -f /$HOME/file ]; do
    	echo "File exists rm?: y or n";	read  ANSWER
    		if [ $ANSWER = "y" ]
    		then
    		rm -r /$HOME/file
    		echo "File removed"
    		elif [ $ANSWER = "q"]
    		then
    		echo "Script exiting"
    		exit 0
    		else 
    		echo "File exists, script terminating"
    
    	fi
    done
    if [ !-f /$HOME/file ]
    	then "File does not exist. Do you wish to create it? :y or n"
    	read -p': '  ANSWER2
    		if [  "$ANSWER2" = "y" ]
    		then 
    		touch file
    		echo $ANSWER2 "File created, script terminated"
    		else
    		echo $ANSWER2 "File not created, script terminated"
    	fi
    fi
    Sorry, I fixed it. Turns out its good to step away for a little bit.

    Code:
    #!/bin/bash 
    while [ -f /$HOME/file ]; do
    	echo "File exists rm?: y or n"
    	read  ANSWER
    		if [ $ANSWER = "y" ]
    		then
    		rm -r /$HOME/file
    		echo "File removed"
    		elif [ $ANSWER = "q" ]
    		then
    		echo "Script exiting"
    		exit 0
    		else 
    		echo "File exists, script terminating"
    		exit 0
    
    	fi
    done
    if [ ! -f /$HOME/file ]
    	then 
    	echo "File does not exist. Do you wish to create it? :y or n"
    	read -p': '  ANSWER2
    		if [ "$ANSWER2" = "y" ]
    		then 
    		touch file
    		echo $ANSWER2 "File created, script terminated"
    		else
    		echo $ANSWER2 "File not created, script terminated"
    	fi
    fi
    Sorry, for the inconvenience. This can be deleted now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...