Solved

sh file if statement for user input Y/N

Posted on 2011-02-13
3
656 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

688 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