hi,
I have some problems in my simple script about the redirect echo stdout command inside a condition. Why is the echo command inside the elif still execute in the else command
Here are my simple script
#!/bin/bash
filename=`zenity --entry --text "Output Filename"`
location=`pwd`
pwd1="/mnt/Data/Ebooks-Video_Tutorials"
date=`date +%Y-%m-%d`
if [ -z $filename ];then
exit 1
elif [ -d $location -a -d $pwd1 ];then
echo "######### $location root directory ######### " > "$filename"\ Full\ Path-$date.txt
find "$location" -type f | sed 's/\/mnt\/Data\/Ebooks-Video_Tutorials\///g' | sort | grep -v "$filename" >> "$filename"\ Full\ Path-$date.txt
else
find "$location" | sort | grep -v "$filename" > "$filename"\ Full\ Path-$date.txt
fi
After check on the two diff output the echo stdout redirect is present in two diff outputs.
Thanks for any input..
If it's present in both outputs, then it's taking the first branch in both outputs.
Can you explain it for me..If you dont mine..
It is executing this code block both times:
elif [ -d $location -a -d $pwd1 ];then
echo "######### $location root directory ######### " > "$filename"\ Full\ Path-$date.txt
find "$location" -type f | sed 's/\/mnt\/Data\/Ebooks-Video_Tutorials\///g' | sort | grep -v "$filename" >> "$filename"\ Full\ Path-$date.txt
else