Logo 
Search:

Unix / Linux / Ubuntu Articles

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

Write a shell script, which will receive any number of filenames as arguments .The shell script should check whether such files already exist.

Posted By: Reginald Fischer     Category: Unix / Linux / Ubuntu     Views: 5628

Write a shell script, which will receive any number of filenames as arguments .The shell script should check whether such files already exist. If they do, then it should be reported. If these files do not exist then check if a subdirectory called mydir exists in the current directory .If it doesn’t exist then it should be created and in it files supplied as arguments should get created .If mydir already exists then it should be reported along with the number of files that are currently present in myir.

Code for Write a shell script, which will receive any number of filenames as arguments .The shell script should check whether such files already exist. in Unix / Linux / Ubuntu

while [ $# -ne 0 ]
doif [ -e $1 ] 
    then
        echo "File already exist"elseif [ -d mydir ]
        then
            cd mydir    
            i=`ls -f | grep -c /`
            c=`ls -1 | wc -l`
            echo "Total File in current dir : " `expr $c - $i`    
        else
            mkdir mydir
            cd mydir
            touch $1
        fi
        cd ..
    fi
    shift
done             
  
Share: 



Reginald Fischer
Reginald Fischer author of Write a shell script, which will receive any number of filenames as arguments .The shell script should check whether such files already exist. is from Frankfurt, Germany.
 
View All Articles

Related Articles and Code:


 
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!