Write Bash Script Called Move Could Replace Unix Command Mv Move Tries Rename Source File Q37082901

Write a Bash script called move that could replace the UNIXcommand mv. ‘move’ tries to rename the source file (using the UNIXcommand mv), but if the destination file exists, appends an indexnumber, a sort of version number, to the destination file. So ifthe user types:

move a.txt b.txt

and b.txt already exists, move will rename the file to b.txt.1.If b.txt.1 already exists, move must rename the file to be b.txt.2,and so on, until the file can be successfully renamed with a namethat does not already exist.


Solution


BashScript:

#!/bin/bash

# Fetching file name from arguments
SFile=”$1″
DFile=”$2″
name=$DFile
serial=1

while [ 1 ]
do
   # Checking for existence of file
  

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.