f



"cat <> file" and "echo "ddd" >&2 2>&1" questions

Hi All

1.
what is "cat <> file" means?
is that means read line ,echo to stdout ,and write back to file?
but I think command should be "cat <>> file" which fails.

2.
$echo "ddd" >&2 2>&1
ddd
$echo "ddd"  2>&1 >&2
ddd
$

which "fd" be used on earth?
Is there any way to display what fd be used?
like :
$echo "ddd"
1:ddd

thanks



0
Key9
8/19/2007 12:56:32 PM
comp.unix.shell 15484 articles. 3 followers. Post Follow

5 Replies
990 Views

Similar Articles

[PageSpeed] 56

On Sun, 19 Aug 2007 20:56:32 +0800, Key9 wrote:

> Hi All
> 
> 1.
> what is "cat <> file" means?
> is that means read line ,echo to stdout ,and write back to file? but I
> think command should be "cat <>> file" which fails.

The tokenizer for the shell recognises '>' '>>' '<' and '<>' as distinct 
tokens.

The '<>' token (which can be preceeded by a digit) opens the file given 
for reading and writing.

In this case as 'cat' only expects stdin to be opened for reading, it is 
the same as typing "cat < file" if the file is writeable (if it isn't you 
will get a permission denied).

> 2.
> $echo "ddd" >&2 2>&1
> ddd

File discriptor manipulation is done left to right. So this says
a) send fd1 to where fd2 points
b) send fd2 to where fd1 points. Clearly this is redundant as fd1 and 2 
point to the same place.

Then send ddd and a newline to fd 1.

> $echo "ddd"  2>&1 >&2
> ddd
> $

a) send fd2 to where fd1 points
b) send fd1 to where fd2 points. Equally redundant

Then send ddd and a newline to fd1.

> which "fd" be used on earth?
echo always writes to fd1

> Is there any way to display what fd be used? like :
> $echo "ddd"
> 1:ddd

NO, but as echo always uses fd1 there is little point.
0
Icarus
8/19/2007 3:47:12 PM
In article <fa9em7$e8h$1@news.yaako.com>, Key9 <publicaccept@163.com> wrote:
>which "fd" be used on earth?
>Is there any way to display what fd be used?
>like :
>$echo "ddd"
>1:ddd

If you're wondering how to tell which of the open fds that a program inherits
it is writing output to, this utility may help:
ftp://ftp.armory.com/pub/scripts/fdshow

Example:

$ fdshow echo ddd
1: ddd

	John
-- 
John DuBois  spcecdt@armory.com  KC6QKZ/AE  http://www.armory.com/~spcecdt/
0
spcecdt
8/22/2007 4:30:35 PM
In article <13cop5bbqo1ap24@corp.supernews.com>,
John DuBois <spcecdt@armory.com> wrote:
>In article <fa9em7$e8h$1@news.yaako.com>, Key9 <publicaccept@163.com> wrote:
>>which "fd" be used on earth?
>>Is there any way to display what fd be used?
>>like :
>>$echo "ddd"
>>1:ddd
>
>If you're wondering how to tell which of the open fds that a program inherits
>it is writing output to, this utility may help:
>ftp://ftp.armory.com/pub/scripts/fdshow
>
>Example:
>
>$ fdshow echo ddd
>1: ddd

fdshow: Command not found.

0
gazelle
8/23/2007 1:39:51 PM
"Kenny McCormack" <gazelle@xmission.xmission.com> schrieb im Newsbeitrag 
news:fak2n7$cj9$3@news.xmission.com...
> In article <13cop5bbqo1ap24@corp.supernews.com>,
> John DuBois <spcecdt@armory.com> wrote:
>>In article <fa9em7$e8h$1@news.yaako.com>, Key9 <publicaccept@163.com> 
>>wrote:
>>>which "fd" be used on earth?
>>>Is there any way to display what fd be used?
>>>like :
>>>$echo "ddd"
>>>1:ddd
>>
>>If you're wondering how to tell which of the open fds that a program 
>>inherits
>>it is writing output to, this utility may help:
>>ftp://ftp.armory.com/pub/scripts/fdshow
>>
>>Example:
>>
>>$ fdshow echo ddd
>>1: ddd
>
> fdshow: Command not found.
Have you botherd to look at ftp://ftp.armory.com/pub/scripts/fdshow?

If I run it I get
fdshow[127]: syntax error at line 129 : `==' unexpected

Bye, Jojo 


0
Joachim
8/23/2007 2:46:03 PM
In article <fak6m8$v9a$1@usenet01.boi.hp.com>,
Joachim Schmitz <schmitz@hp.com> wrote:
>> In article <13cop5bbqo1ap24@corp.supernews.com>,
>> John DuBois <spcecdt@armory.com> wrote:
>>>If you're wondering how to tell which of the open fds that a program 
>>>inherits it is writing output to, this utility may help:
>>>ftp://ftp.armory.com/pub/scripts/fdshow
>
>If I run it I get
>fdshow[127]: syntax error at line 129 : `==' unexpected

I'm not sure what ksh would produce that result - perhaps pdksh?
(I don't have pdksh to test with.)

	John
-- 
John DuBois  spcecdt@armory.com  KC6QKZ/AE  http://www.armory.com/~spcecdt/
0
spcecdt
8/24/2007 4:13:56 AM
Reply: