KSH Redirect to Pipe (">|") Syntax


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting KSH Redirect to Pipe (">|") Syntax
# 1  
Old 10-26-2010
KSH Redirect to Pipe (">|") Syntax

Occasionally I see this in ksh scripts:

somepgm >| someoutputfile

This appears to be redirecting the output of somepgm to the file someoutputfile, and it does do so.

But when you remove the pipe symbol "|" from this command, output simply goes to the screen (stdout). Why do we need the pipe symbol here in order to get output to go to the file?

Is there something special (or wierd) that somepgm must be doing so that one has to use the ">|" to get its output redirected to a file?
# 2  
Old 10-26-2010
ksh man says >| overrides noclobber, so it will not work if the file exists, but I am not sure why you get screen output.
# 3  
Old 10-26-2010
Please show us what you get on screen & the code of somepgm.

Is someoutputfile a normal file ?
# 4  
Old 10-26-2010
Unfortunately, I can't show the source code of somepgm - I do not have it. But one example of somepgm is a data file utility which reformats a binary file into a flat text file. When this utility is run without the ">|" but rather only the ">" redirector, the flat text is output to the screen instead of to the somedata file.

I'm wondering if the source code would reveal that somepgm is looking at the command line parameters, parsing them, and in the absence of ">|" as a "valid" parameter (or is watching for a noclobber exception?), puts the output on stdout?

Can a C/C++ pgm "see" the command line entries, such as redirectors?
# 5  
Old 10-26-2010
No, the > or >| is done by ksh before it starts somepgm, and if it fails, it does not run somepgm, it deals with it as a script failure.

If there is a pipe and a goofy program upstream, it could divert to stdout/fd=1or /dev/tty when the pipe dies unexpectedly.

Does your system have tusc or truss? It provides more information that you can imagine unless you have used it.
# 6  
Old 10-26-2010
Could you write a somepgm shell that simulate the described behaviour ?
so that :
Code:
# somepgm >| someouputfile
# cat someouputfile
Hello World
# somepgm > someouputfile
Hello World
#

# 7  
Old 10-26-2010
I'll try that - should be able to do it tomorrow - have a little bit of a lax schedule then.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Shell Programming and Scripting

What is the right way to redirect script output use ">" or ">>" ?

Which one of the following are more accurate and why? nohup myScript.sh 1>nohup_$(date +%Y%m%d%H%M%S).out 2>&1 & nohup myScript.sh 1>>nohup_$(date +%Y%m%d%H%M%S).out 2>&1 & nohup myScript.sh >nohup_$(date +%Y%m%d%H%M%S).out 2>&1 & nohup myScript.sh >>nohup_$(date +%Y%m%d%H%M%S).out 2>&1 &... (3 Replies)
Discussion started by: kchinnam
3 Replies

5. Shell Programming and Scripting

Purpose of "read" and "$END$" in ksh ?

Hi, Could anyone please shed some light on the following script lines and what is it doing as it was written by an ex-administrator? cat $AMS/version|read a b verno d DBVer=$(/usr/bin/printf "%7s" $verno) I checked that the cat $AMS/version command returns following output: ... (10 Replies)
Discussion started by: dbadmin100
10 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

ksh-script "arithmetic syntax error" comparing strings

Hi all, I´ve already searched the forum but can´t find what i am doing wrong. I am trying to compare two variables using ksh under red hat. The error I get is: -ksh: .: MDA=`md5sum /tmp/ftp_dir_after_transfer | cut -d' ' -f1 ` MDB=`md5sum /tmp/ftp_dir_before_transfer | cut -d' ' -f1 `... (3 Replies)
Discussion started by: old_mike
3 Replies

8. HP-UX

script running with "ksh" dumping core but not with "sh"

Hi, I have small script written in korn shell. When it is called from different script, its dumping core, but no core dump when we run it standalone. And its not dumping core if we run the script using "/bin/sh" instead of "ksh" Can some body please help me how to resolve this issue. ... (9 Replies)
Discussion started by: simhe02
9 Replies

9. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question