I generally don't deal with scripting outside of Batch (and even that's a little hazy after all these years) and i've never dealt with Linux. Luckily, it looks very similar to batch, so i'll give it a shot, but you'll potentially need to correct folder locations and check the syntax.
This is what i assume is the problem. As others said, you've not created the variable "location1". Typically in 'system scripting' language, variables are assigned like this;
Code:
variablename=variable_data
To use the variable, something like this;
Code:
echo "$variablename"
For example, if you wanted to set a location variable called 'location1' to '/root/michael/store' (this is just an assumption), you'd have this;
Code:
location1=/root/michael/store
and to echo that to screen;
To use a variable in any way, it's literally adding a dollar sign ($) before the name of the variable you wish to use.
This is a basic definition and is fairly universal. Programming isn't much different, but i won't go into that here as it's not the subject.
I'd guess the second part (after 'else' is where the problem lies). Step by step, you're;
1 - Setting the directory
2 - Calling the restore command with '$2'
3 - Setting the filename variable to `basename "$restore"`
4 - Attepting to move/mv the file specified in step 3 from "location1" to $location, telling it to prompt before overwrite
To me, there's one main problem; "$location". You've not specified in the script what that is and you're trying to move files there. Usage of mv according to research shows something like this;
Code:
mv [flags] Source Destination
Traditionally, you might enclose source and destination in speech marks ("Source" "Destination") unless it's a variable to form something like this;
Code:
mv -i $filename $location
From that last line of the script, it's like it's looking for the directory "location1" inside $filename.
I'm not sure if this will fix it (and i'm not responsible if it messes anything up or simply doesn't work, use at your own risk);
Code:
if [ "$1" == "-n" ]
then
cd /root/michael/trash
restore`grep "$2" /root/michael/store`
filename=`basename "$restore"`
echo "Where would you like to save the file?"
read location
location1=`readlink -f "$location"`
mv -i $filename "location1"/filename
else
location=`/insert/your/location/here`
cd /root/michael/trash
restore=`grep "$2" /root/michael/store`
filename=`basename "$restore"`
mv -i $filename "location1" $location
fi
You might also want to look at that last mv line in the original script you posted. Is there not meant to be a slash somewhere in there? I'm not sure whether you want to move from $filename/"location1" to $location, or from $filename to "location1"/$location. That alone would probably cause the script to bug out, but combined with the variable(s) you were missing, i'd hazard it's simply not knowing what you're intending to actually move.
Again, it's all guesswork, but i believe that's the issue.