Solved

sh file if statement for user input Y/N

Posted on 2011-02-13
3
650 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
LINUX ZIP - UNCOMPRESS WINDOWS PATH 3 109
Remote install of MSI file 4 54
Unix Command (AIX) 3 42
Extract Proxy Server  from Proxy PAC file in DOS BATCH File 4 22
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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…

726 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