Unix/Linux Go Back    


Shell Programming and Scripting 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

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 11-02-2011   -   Original Discussion by jao_madn
jao_madn jao_madn is offline
Registered User
 
Join Date: Aug 2007
Last Activity: 30 December 2012, 6:16 AM EST
Posts: 113
Thanks: 9
Thanked 1 Time in 1 Post
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..
Sponsored Links
    #2  
Old Unix and Linux 11-02-2011   -   Original Discussion by jao_madn
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 16 November 2017, 10:25 AM EST
Location: Saskatchewan
Posts: 22,508
Thanks: 1,151
Thanked 4,273 Times in 3,946 Posts
If it's present in both outputs, then it's taking the first branch in both outputs.
Sponsored Links
    #3  
Old Unix and Linux 11-02-2011   -   Original Discussion by jao_madn
jao_madn jao_madn is offline
Registered User
 
Join Date: Aug 2007
Last Activity: 30 December 2012, 6:16 AM EST
Posts: 113
Thanks: 9
Thanked 1 Time in 1 Post
Quote:
Originally Posted by Corona688 View Post
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 Unix and Linux 11-02-2011   -   Original Discussion by jao_madn
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 16 November 2017, 10:25 AM EST
Location: Saskatchewan
Posts: 22,508
Thanks: 1,151
Thanked 4,273 Times in 3,946 Posts
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

Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
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
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 05:20 PM.