I have been able to solve my problem. In case it will be useful for somebody,let me explain.
Use the following script :
mysql -u [username ] -p[password] [db_name] -e " SELECT * FROM [tbl_name] ">/path_to_file/file_name
That is all and the output of the file_name will contain the query result of SELECT command.
if you do not specify username and password and even the database name ,you will not be able to this will not work. Also I later realise that the option -e to the mysql command means execute in mysql> command prompt. so you can execute anything using that format as if you are in mysql> comand prompt.
Again, it is required that /path_to_file directory be world writeable(drwxr-xrwx) eg by using chmod 757 command. /tmp is ideal for this as it has this property already.
These are the mistakes I was making for the past 3 days until I was able to solve the problem.