Solved

sh file if statement for user input Y/N

Posted on 2011-02-13
3
638 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
Comment Utility
if [ "$movefile" =  "Y" ]: then ...

Note the spaces and the quotes!

wmp
0
 
LVL 68

Expert Comment

by:woolmilkporc
Comment Utility
Sorry, there must be a semicolon ; following ] !

Those tiny Smartphone keys ...
0
 

Author Closing Comment

by:cghrmauritius
Comment Utility
Thanks you so much for the quick response worked perfectly
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
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 find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

744 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

10 Experts available now in Live!

Get 1:1 Help Now