views:

168

answers:

4

Pasted a piece of code from the shell script transfer.sh

        if [[ ${ld} -eq ${eld} ]] ; then
            mv "$file1" "$FILESNEW/."
            if [ $? -ne 0 ]; then
               echo "Move Command Failed-File ${fspec}"
            fi

            echo  "File ${fspec} Sucessfully Moved to ready directory "
        else
          echo "File ${fspec} line count mismatch: ${lc}/${elc}"
        fi

when i execute ./transfer.sh move command waits for a prompt "override protection y/n" I dont want this prompt to appear when move command gets executed. How can i get rid of it?

+1  A: 

change mv to mv -f

Man page for mv

But remember, -f to force it means it won't prompt you so you better be sure you know how it's going to be used.

John Weldon
Thanks a lot for the info
Arav
+1  A: 

Use mv -f. Option -f overrides any prompts ("force").

-f, --force

do not prompt before overwriting
sleske
+1  A: 

try

   if [[ ${ld} -eq ${eld} ]] ; then
        mv -f "$file1" "$FILESNEW/"
        ....
ghostdog74
Thanks a lot for the info
Arav
A: 

change:

mv "$file1" "$FILESNEW/."

to:

/bin/mv "$file1" "$FILESNEW/."

(or wherever mv is located on your machine)

eqbridges
Thanks a lot for the info
Arav
The problem wasn't an inability to find "mv"
gary
@gary: But most likely `mv` was an alias, and using `/bin/mv` works because `mv` by default doesn't ask for confirmation.
Alok
exactly. the problem with what I propose is the need to hardcode the path, yet there are ways around that (e.g. ``which mv``). if there's an alias, adding switches may confuse the situation further.
eqbridges
Still No-Go. Bypassing an alias won't fix the problem if the existing file does not have write permission. In that case, the default is to ask for confirmation. If trying to avoid an aliased "-i" was eqbridges's true intention, eqbridges deserves another down-vote for being unnecessarily obscure in proposing a solution.
gary
Hmmm, trying to move a file that does not have write permission does not lead to `mv` asking for confirmation. At least with GNU coreutils v7.0. I also tried this with a read-only directory, and a read-only destination file (i.e. 0444).Or, did you mean something else?
eqbridges