3 ms·
I once had to edit a file while logged in on console and where I literally had nothing but the Bourne shell to work with. I eventually figured out a while loop
by js2 8y ago
I once had to edit a file while logged in on console and where I literally had nothing but the Bourne shell to work with. I eventually figured out a while loop which read a line at the time from the file, echoed it, then read a line from the tty, where typing just return meant to keep the line as is, else use the line I typed, and sent the output to a new file. I then used shell redirection to replace the old file. Maybe I had "cat" too.
That was tedious.
It was circa 1995 on an HP/UX machine that was nothing but an X terminal, but its root disk for some reason only had the minimum of files that it needed to mount everything else via NFS, but somehow all the automounts had become misconfigured.
As I recall anyway.
And here's a network calculator I wrote mostly in awk:
https://gist.github.com/jaysoffian/e41ca479d70e60efe59fded93528ab1b https://gist.github.com/jaysoffian/e41ca479d70e60efe59fded93...
- tyingq 8y agoecho `<somefile` Uses a shell built in and can substitute for cat.
- pronoiac 8y ago'cat > somefile' is my first instinct, but the while loop described allows for editing, rather than wholesale replacement.
- tyingq 8y agoI was thinking of situations like described in the GP, where most external commands would be unavailable. Aside from what was described there, screwing up the shared libc is also common. Where you're left with a functional shell if you were logged in, but no external commands, except for /sbin/ stuff. The hack with echo mostly works, but will have issues with large files due to limits on arg length.