Logo 
Search:

Unix / Linux / Ubuntu Articles

Submit Article
Home » Articles » Unix / Linux / Ubuntu » Homework HelpRSS Feeds

Suppose four filenames are supplied then the first file should get copied into second file, the third file should get copied into four

Posted By: Isabella Campbell     Category: Unix / Linux / Ubuntu     Views: 6955

A shell script receives even number of filenames. Suppose four filenames are supplied then the first file should get copied into second file, the third file should get copied into fourth file, and so on. If odd number of filenames are supplied then no copying should take place and an error message should be displayed.

Code for Suppose four filenames are supplied then the first file should get copied into second file, the third file should get copied into four in Unix / Linux / Ubuntu

CheckNo=`expr $# % 2`
    if [ $CheckNo -ne 0 ]
    then
            echo "Enter Even Number Of Arguments."else
            cnt=1
            while [ $cnt -lt $# ]
            do
                    cp $1 $2
                    shift
                    shift
                    cnt=`expr $cnt + 2`
            done
    fi

--------------------------------------------------------------------------------

output:
$ sh29 detail.txt temp

$ cat detail.txt
NAME : YAGNIK VIDYADHAR
AGE  : 22
ADDR : VASNA.

$ cat temp
NAME : YAGNIK VIDYADHAR
AGE  : 22
ADDR : VASNA.

$ sh29 detail.txt
Enter Even Number Of Arguments.

$ sh29 detail.txt temp1 temp2
Enter Even Number Of Arguments.
  
Share: 



Isabella Campbell
Isabella Campbell author of Suppose four filenames are supplied then the first file should get copied into second file, the third file should get copied into four is from Toronto, Canada.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!