Results 1 to 1 of 1
I want to rite a Linux shell script that takes two arguments. These arguments can be files or directories. If two files are supplied, check if they have the same ...
- 07-03-2011 #1Banned
- Join Date
- Jul 2011
- Posts
- 1
[HELP!]Program still executable but the logic messed up
I want to rite a Linux shell script that takes two arguments. These arguments can be files or directories. If two files are supplied, check if they have the same content and print a success or failure outcome. If first argument is a file and the other is a directory, check if files exist in directory and copy it if it is a newer version. If it does not exist, create a link in target directory. If first argument is a directory and second argument is a file, I will be prompted to choose whether to archive content of directory to file or extract archive from file to directory. If two arguments are directories, copy all files in first directory to second directory. Also, I have to make sure that newer versions of files only are copied and report on each file when it is not the case. And also all error should be handle by error checking.
So far im not sure what i did is rite, some logic error occured in my program although it doesn have any error
code:
The first condition is ok which take 2 files as arguments and gave me what i want. but not the 2nd condition. TheCode:if [ $# -ne 2 ] then echo "Error:$0 does not have valid input." echo "Please enter 2 valid input." fi if test -f $1 && test -f $2 then d=$(diff $1 $2) if [ -z $d ] then echo "File is same" else echo "File is different" fi fi if test -f $1 && test -d $2 then find $2 -name $1 -print cp $1 $2 echo "1 file copied." else ln $2 $1 echo "Link created." fi if test -d $1 && test -f $2 then read "Choose Y to archive content of directory to file or N to extract archive from file to directory: " r1 if $r1 = Y || $r1 = y then tar -cvf $2.tar $1 echo"Archive directory success." elif $r1 = N || $r1 = n then tar -xvf $2.tar -C $1 echo" Extract archive success." fi fi if test -d $1 && test -f $2 then cp $1 $2 echo"All files copied." fi
does not display even i met the condition. This same goes the 3rd condition. I knw it's difficult to understand and help with tis program. But at least try to give me some tips so i knw how far im going now.Code:ln $2 $1 echo "Link created."


Reply With Quote