Hi, I'm trying to write s simple script, that will check if a file exists and echo if found or not. Here is a piece of the script.
Code:
#!/bin/bash
if [ "$#" -ne 1 ]; then
echo "$(color ltgreen)usage: $(color off)$0 $(color ul)<argument>$(color off)";
else
if [ -e $1.tar.bz2 ]; then
echo "$1.tar.bz2";
exit 0
else
if [ ! -e $1.tar.bz2 ] && [ ! -e $1.tar.gz ]; then
echo "$(color ltred).::ERROR::.$(color off):$(color ul)no$(color off) file found"
exit 1
else
if [ -e $1.tar.bz2 ] && [ -e $1.tar.bz2 ]; then
echo "Both Exist!!";
else
echo "$1.tar.gz";
exit 1
fi
fi
fi
fi
So what it basically does is to check if the user's input exists in a "tar.bz2" file or "tar.gz" file. It kinda works, but I noticed if a tar.bz & a tar.gz of the same name exist, it only outputs the tar.bz2 filename. Is there a simpler (or even better way to do this)