Free Republic
Browse · Search
General/Chat
Topics · Post Article

To: dayglored
Someone has written a M-x butterfly, you know ...

When your company server won't boot because of problems in /etc/fstab, you can't get fsck to act sanely, and you're in a single-user shell with your boss staring at you -- even vi is not available -- use ed.

In upper division college, I was finally off of the System 7 PDP and on the CS VAX which had vi available and ... I couldn't use it most of the time because it was too slow, so I still used ed.

But, question ... how do you edit files using only /bin/sh if for some reason ed isn't available? I figured it out under fire when I was trying to get a Microport install working until I established that it didn't have drivers for the hard disk for the machine.

54 posted on 09/12/2010 1:13:31 PM PDT by altair (Violence is the last refuge of the incompetent - Salvor Hardin)
[ Post Reply | Private Reply | To 51 | View Replies ]


To: altair
> But, question ... how do you edit files using only /bin/sh if for some reason ed isn't available?

Well, it's stretching the definition of "edit", but as long as the file is less than about 15 lines (assuming a 24x80 console), and /bin/cat is available:

cat file_to_be_edited
cat > file_to_be_edited
and type carefully, using the first printout as a guide.

If you're really stuck with only /bin/sh and don't even have cat, there's always:

$ echo "line one
> line two
> ... " >
file_to_be_edited
assuming echo is a built-in and not /bin/echo.

I use cat > or echo > typically at least once a day, for creating short textfiles of a line or two, such as motd or for testing or flagging purposes. I feel sorta silly cranking up an editor for something I can type in the time it takes for the editor come up and shut down.

Another handy cat hint, if you're using X11 and need to copy/paste some text while removing formatting (say you're copying formatted text from a browser into a plaintext file):

cat >/dev/null
paste the formatted text here
^D
The xterm throws away the formatting, and you can then select-copy from the xterm's echoed display, and paste to the plaintext file. I use that so often I made it an alias "catnul". :)
57 posted on 09/12/2010 2:20:59 PM PDT by dayglored (Listen, strange women lying in ponds distributing swords is no basis for a system of government!)
[ Post Reply | Private Reply | To 54 | View Replies ]

To: altair
I don't think I actually answered your question. :)

> I figured it out under fire...

That implies you could really -edit- a file using only /bin/sh and no other binaries.

All I can think is something like:

exec < file_to_be_edited
while read line; do
  (some shell magic with line)
  echo "$line" >>
new_file
done
or maybe instead of a single variable line, use a series of variables for each word parsed from the input on each line.... argggh. And you'd still have to use mv to rename it back, so that can't be right.

I'd love to know how; willin' to share?

58 posted on 09/12/2010 2:35:21 PM PDT by dayglored (Listen, strange women lying in ponds distributing swords is no basis for a system of government!)
[ Post Reply | Private Reply | To 54 | View Replies ]

Free Republic
Browse · Search
General/Chat
Topics · Post Article


FreeRepublic, LLC, PO BOX 9771, FRESNO, CA 93794
FreeRepublic.com is powered by software copyright 2000-2008 John Robinson