You are not logged in.

#1 2009-10-23 02:32:42

matthewbauer
Member
From: /usa/ks
Registered: 2009-07-20
Posts: 86

Write Command in Shell

Is there a write command in shell? It seems like there should be, but I guess most people just use the ">" and "<" symbol. It just seems like it would make things simpler to just use the "|" pipe symbol.


Libertarian Arch Linux User

Offline

#2 2009-10-23 03:44:47

sand_man
Member
From: Australia
Registered: 2008-06-10
Posts: 2,164

Re: Write Command in Shell

How would that make things simpler exactly?


neutral

Offline

#3 2009-10-23 05:41:44

chpln
Member
From: Australia
Registered: 2009-09-17
Posts: 361

Re: Write Command in Shell

Have a look at 'tee', which reads from stdin and writes (or optionally appends) to a file.  However, a side effect of this is that it also writes to stdout.

Offline

#4 2009-10-23 06:01:01

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,231
Website

Re: Write Command in Shell

Is this what you mean?

cat > output-file.txt <<EOT
This is a file. Files are cool.

It is multiline too. How awesome.
EOT

Last edited by fukawi2 (2009-10-23 06:01:19)

Offline

#5 2009-10-23 08:41:11

sand_man
Member
From: Australia
Registered: 2008-06-10
Posts: 2,164

Re: Write Command in Shell

What's EOT? I've only seen that as EOF.


neutral

Offline

#6 2009-10-23 09:05:43

Aprz
Member
From: Newark
Registered: 2008-05-28
Posts: 277

Re: Write Command in Shell

sand_man wrote:

What's EOT? I've only seen that as EOF.

Well, it doesn't matter... it could be ABC and still work, but I am guessing he put T for Text instead of F for File... or typo... whatever. wink

Offline

#7 2009-10-23 09:07:58

ZankerH
Member
Registered: 2009-02-06
Posts: 95

Re: Write Command in Shell

matthewbauer wrote:

Is there a write command in shell? It seems like there should be, but I guess most people just use the ">" and "<" symbol. It just seems like it would make things simpler to just use the "|" pipe symbol.

How is it "easier"? It's people like you who commit cat abuse.

Last edited by ZankerH (2009-10-23 09:08:16)

Offline

#8 2009-10-23 09:37:12

hbekel
Member
Registered: 2008-10-04
Posts: 311

Re: Write Command in Shell

sand_man wrote:

What's EOT? I've only seen that as EOF.

EOT = End Of Transmission
EOF = End Of File

They're synonyms, as far as I see. ascii(7) calls it EOT while it's called eof for stty(1), still both mean \x04.

Offline

#9 2009-10-23 12:09:52

xd-0
Member
From: Sweden
Registered: 2007-11-02
Posts: 327
Website

Re: Write Command in Shell

cat > file
blaha random
text etc...

then ctrl+d to close cat.

Or

echo -e "some random text \n in a file" > file

Offline

#10 2009-10-23 13:43:43

Barrucadu
Member
From: York, England
Registered: 2008-03-30
Posts: 1,158
Website

Re: Write Command in Shell

I think he means something like this:

$ some command here | write /path/to/file

To remove the > symbol. Presumably such a command would have an optional argument to have append functionality, removing the >> symbol.

Offline

#11 2009-10-23 14:04:35

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: Write Command in Shell

as already mentioned, 'tee' does this, but it also prints to stdout.


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

#12 2009-10-23 14:11:26

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,799
Website

Re: Write Command in Shell

done.

//blue/0/~ write() { tee - "$1" &>/dev/null ; }
//blue/0/~ echo some text | write somefile
//blue/0/~ cat somefile
some text

big_smile

Offline

#13 2009-10-23 15:49:37

fsckd
Forum Fellow
Registered: 2009-06-15
Posts: 4,173

Re: Write Command in Shell

What is this obsession with tee?

> write () { dd of="$1" &> /dev/null ; }
> echo some text | write somefile
> cat somefile
some text

Edit: Real men use dd or you can just use cat > "$1".

Last edited by fsckd (2009-10-23 16:01:23)


aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies

Offline

#14 2009-10-23 16:19:32

Lich
Member
Registered: 2009-09-13
Posts: 437

Re: Write Command in Shell

fsckd wrote:

What is this obsession with tee?

> write () { dd of="$1" &> /dev/null ; }
> echo some text | write somefile
> cat somefile
some text

Edit: Real men use dd or you can just use cat > "$1".

Some of those real men end up with corrupted HDDs when they're not careful big_smile


Archlinux | ratpoison + evilwm | urxvtc | tmux

Offline

#15 2009-10-23 22:03:49

matthewbauer
Member
From: /usa/ks
Registered: 2009-07-20
Posts: 86

Re: Write Command in Shell

OK, so tee is what I was looking for thanks.

I just think it seems like it would make things simpler to use a command, instead of introducing a new symbol, and give you more options.


Libertarian Arch Linux User

Offline

#16 2009-10-23 22:19:57

ZankerH
Member
Registered: 2009-02-06
Posts: 95

Re: Write Command in Shell

matthewbauer wrote:

OK, so tee is what I was looking for thanks.

I just think it seems like it would make things simpler to use a command, instead of introducing a new symbol, and give you more options.

Using > means one less process compared to cat/dd abuse.

I hereby nominate the OP for the UUOC award.

Offline

#17 2009-10-23 22:23:33

sctincman
Member
From: CO (USA)
Registered: 2009-04-08
Posts: 85

Re: Write Command in Shell

ZankerH wrote:

I hereby nominate the OP for the UUOC award.

I'm pretty sure he never once mentioned cat :P

Offline

#18 2009-10-24 04:46:10

sand_man
Member
From: Australia
Registered: 2008-06-10
Posts: 2,164

Re: Write Command in Shell

Kind of off topic but does anyone know if tee existed in the old UNIX days? or is it a newer Unix-like app?


neutral

Offline

#19 2009-10-24 05:29:19

chpln
Member
From: Australia
Registered: 2009-09-17
Posts: 361

Re: Write Command in Shell

It is a standard UNIX command (see Single UNIX Specification) and found in a whole host of UNIX derivatives (plus other platforms).  Though I couldn't find exactly when it originated.

Offline

#20 2009-10-24 05:47:41

Acecero
Member
Registered: 2008-06-21
Posts: 1,373

Re: Write Command in Shell

sand_man wrote:

Kind of off topic but does anyone know if tee existed in the old UNIX days? or is it a newer Unix-like app?

I've look around all over also, no indication of where it first appeared, and I even looked here. My guess, it's a newer Unix-like app.

Offline

#21 2009-10-24 12:36:46

fsckd
Forum Fellow
Registered: 2009-06-15
Posts: 4,173

Re: Write Command in Shell

I can verify it was on Minix 1 (1980's). Here is the man page (very short!):

Command:        tee - divert standard input to a file
Syntax:         tee [-ai] file ...
Flags:          -a       append to the files, rather than overwriting
                -i       ignore interrupts
Examples:       cat file1 file2 | tee x # Save and display two files
                pr file | tee x | lpr   # Save the output of pr on x

     Tee copies standard input to standard output.  It also makes copies on
all the files listed as arguments.

Edit: It looks like it is an old UNIX command. You can find its manual entry for Version 7 UNIX under volume 1, section 2 here or here.

Last edited by fsckd (2009-10-24 13:10:44)


aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies

Offline

#22 2009-10-24 14:19:29

tlvb
Member
From: Sweden
Registered: 2008-10-06
Posts: 297
Website

Re: Write Command in Shell

matthewbauer wrote:

I just think it seems like it would make things simpler to use a command, instead of introducing a new symbol, and give you more options.

But then instead you are introducing a new command. And you would still need to use | so it cannot really be for the reason that alphanumeric combinations are easier to remember than any other character...
Oh well, to each their own I guess...

Last edited by tlvb (2009-10-24 14:20:12)


I need a sorted list of all random numbers, so that I can retrieve a suitable one later with a binary search instead of having to iterate through the generation process every time.

Offline

Board footer

Powered by FluxBB