March 8th, 2011, 11:48 PM
is there a way to check if one filename is the same as another? I've tried writing a script called samefile, which takes in 2 arguments, each being a file and compares their names
This is what I have so far:
if [ $1 != $2 ]
echo "The two files are not the same!"
elif [ $1 = $2 ]
echo "The two files are the same!"
Clearly this does not work, so that's why I'm posting here. Please help!
March 9th, 2011, 11:32 AM
Originally Posted by Trinimini
if [ ! "$1" = "$2" ]
echo "The two file names are not the same!"
echo "The two file names are the same!"
April 17th, 2011, 02:37 PM
- sure you know, file names are unique in A dir
so $1 and $2 have different path
that 'if' will always return 1
you must use 'basename $1'
- the 'if' statement for a string comp is not the best way, use 'case'
- that 'else' AFTER an 'exit' is really useless
- check for number of params
- also use different exit codes
- try something like
case $# in 2) ;; *) echo wrong # params; exit 1;; esac
case `basename $1` in `basename $2`)
echo $1 and $2 have the same basename; exit 0;; esac
echo $1 and $2 have different basename
working on Solaris[5-9], preferred languages french and C.