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.

Command output redirection to file issues

Shell Programming and Scripting


Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 06-15-2017   -   Original Discussion by ananan
ananan ananan is offline
Registered User
 
Join Date: Jun 2017
Last Activity: 12 July 2017, 2:38 AM EDT
Posts: 22
Thanks: 5
Thanked 0 Times in 0 Posts
Command output redirection to file issues

Hi,

I have a peculiar issue w.r.t redirecting the command output to a file when using loop.

I am redirecting command output to same file in a series of if condition statements, but if one block of if condition statement writes the log to the file , the subsequent block of if condition satisfied command outputs not logged to the output file.

Second If condition statement will begin after completion of first if...fi block only.
Sponsored Links
    #2  
Old Unix and Linux 06-15-2017   -   Original Discussion by ananan
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 21 November 2017, 2:20 PM EST
Location: Aachen, Germany
Posts: 11,638
Thanks: 320
Thanked 3,618 Times in 3,323 Posts
Well, looking into my personal and reliable crystal bowl after a careful and painstaking polish, I can see the answer: "Correct the subsequent block's output redirection!"
Sponsored Links
    #3  
Old Unix and Linux 06-15-2017   -   Original Discussion by ananan
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 21 November 2017, 2:20 PM EST
Location: Aachen, Germany
Posts: 11,638
Thanks: 320
Thanked 3,618 Times in 3,323 Posts
OK, let's become serious:

Please become accustomed to provide decent context info of your problem.
It is always helpful to support a request with system info like OS and shell, related environment (variables, options), preferred tools, and adequate (representative) sample input and desired output data and the logics connecting the two, to avoid ambiguities and keep people from guessing.
    #4  
Old Unix and Linux 06-15-2017   -   Original Discussion by ananan
rbatte1 rbatte1 is offline Forum Staff  
Root armed
 
Join Date: Jun 2007
Last Activity: 21 November 2017, 12:04 PM EST
Location: Lancashire, UK
Posts: 3,373
Thanks: 1,456
Thanked 665 Times in 598 Posts
Can you share your code so we can actually see it? If it is huge, then please post a meaningful skeleton that exhibits the same issue so we can consider it and help you find a solution.

Please post the code wrapped in CODE tags for clarity.



Kind regards,
Robin
Sponsored Links
    #5  
Old Unix and Linux 06-15-2017   -   Original Discussion by ananan
ananan ananan is offline
Registered User
 
Join Date: Jun 2017
Last Activity: 12 July 2017, 2:38 AM EDT
Posts: 22
Thanks: 5
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by RudiC View Post
Well, looking into my personal and reliable crystal bowl after a careful and painstaking polish, I can see the answer: "Correct the subsequent block's output redirection!"
Hi

If I change the file name in the second part it is writing in to that file, but if both files are same only problem occurs.
Sponsored Links
    #6  
Old Unix and Linux 06-16-2017   -   Original Discussion by ananan
ananan ananan is offline
Registered User
 
Join Date: Jun 2017
Last Activity: 12 July 2017, 2:38 AM EDT
Posts: 22
Thanks: 5
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by ananan View Post
Hi

If I change the file name in the second part it is writing in to that file, but if both files are same only problem occurs.
Finally found the issues. I was initializing the file content in the start of the for loop with > and appending to it in the subsequent if loops >>

So for scenarios where nothing to write in the file for the for loop it simply overwrites the existing file while initializing.

Solved
Sponsored Links
    #7  
Old Unix and Linux 06-16-2017   -   Original Discussion by ananan
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 21 November 2017, 3:22 PM EST
Location: Saskatchewan
Posts: 22,518
Thanks: 1,154
Thanked 4,273 Times in 3,946 Posts
Thanks for explaining.

We wouldn't have been able to guess that without seeing it.
Sponsored Links
Reply

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
Command output redirection in script not working haritha.gorijav Shell Programming and Scripting 7 05-22-2012 02:10 AM
output redirection command knowledgeSeeker UNIX and Linux Applications 2 02-04-2012 02:49 PM
Help with tar --append command output redirection pganguly46 Shell Programming and Scripting 0 02-01-2011 05:32 AM
awk output redirection to file learnscript Shell Programming and Scripting 6 03-03-2010 09:35 PM
Output file redirection aagajaba UNIX for Dummies Questions & Answers 1 04-25-2009 01:24 AM



All times are GMT -4. The time now is 07:05 PM.