arguments in bash

This script moves all the doc files to a specified directory. I have managed to put an argument but the problem I am facing is putting the full path where the scripts are moving to, for example I want to run the script like this below

./loo -d then path where im moving the files (i.e ./loo -d the second argument where files are moving to)

i want to replace $To in the existing script with the command argument after -d ...
this code is not working i dont know why....

#!/bin/bash
From="/home/elg19/lone/doc"
To=$2

if [ $1 = -d ]; then
    cd "$From"
    for i in pdf txt doc; do
      find . -type f -name "*.${i}" -exec mv "{}" "$To" \;
    done
fi

im the one who posted that and its not working

Bumping up posts or double posting is not permitted in these forums.

Please read the rules, which you agreed to when you registered, if you have not already done so.

You may receive an infraction for this. If so, don't worry, just try to follow the rules more carefully. The infraction will expire in the near future

Thank You.

The UNIX and Linux Forums.

Continue here: