Home
Man
Search
Today's Posts
Register

BSD, Linux, and UNIX shell scripting Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

redirect stdout echo command in condition A run in condition B

Tags
shell scripts

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 11-02-2011
redirect stdout echo command in condition A run in condition B

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
Quote:
#!/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..
# 2  
Old 11-02-2011
If it's present in both outputs, then it's taking the first branch in both outputs.
# 3  
Old 11-02-2011
Quote:
Originally Posted by Corona688
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..
# 4  
Old 11-02-2011
It is executing this code block both times:

Code:
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

Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
If condition return 0 even when it fails to satisfy te condition Priya Amaresh Shell Programming and Scripting 2 05-10-2013 02:54 AM
Echo not displaying variable in If-Else condition Chetanz Shell Programming and Scripting 13 02-23-2013 06:44 AM
How do I use paste command in while condition?? nikhil jain Shell Programming and Scripting 7 02-15-2013 09:08 AM
Diff command with a condition Prega UNIX for Dummies Questions & Answers 6 09-13-2011 09:06 AM
Difference between [condition] and [[condition]] and ((condition)) when used with if condition soumyabubun HP-UX 2 05-06-2011 02:03 PM
multiple echo statements in if condition wizardofoz Shell Programming and Scripting 2 03-12-2011 04:00 PM
FTP Command inside If condition aryan_styles Shell Programming and Scripting 3 03-08-2010 05:23 AM
STDOUT redirect to a FILE, when fuser command is used !! varungupta UNIX for Advanced & Expert Users 6 01-25-2008 09:51 AM
redirect stderr and/or stdout to /dev/null from command line knc9233 UNIX for Dummies Questions & Answers 1 01-25-2007 12:24 PM


All times are GMT -4. The time now is 03:34 AM.

Unix & Linux Forums Content Copyright 1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password