Solved

sh file if statement for user input Y/N

Posted on 2011-02-13
3
641 Views
Last Modified: 2013-12-26
Hi i have created an sh script and need to create an if statement for user input Y or N,

i have tried the following

echo -n "Do you wish to move this file to the tmp directory?[Y/N]: "
read movefile

echo
if [$movefile == Y]; then
        echo "Moving File to tmp"
else
        echo "you can download the file from "
fi


please can someone correct this for me as when i run the script i get the responce

Do you wish to move this file to the tmp directory?[Y/N]: Y

./search_with_ref_input.sh: line 19: [Y: command not found
you can download the file from

thanks in advance
0
Comment
Question by:cghrmauritius
  • 2
3 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 34885775
if [ "$movefile" =  "Y" ]: then ...

Note the spaces and the quotes!

wmp
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 34885780
Sorry, there must be a semicolon ; following ] !

Those tiny Smartphone keys ...
0
 

Author Closing Comment

by:cghrmauritius
ID: 34885789
Thanks you so much for the quick response worked perfectly
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now