4 ms·
Why did they remove tilde '~' as a convenient shortcut for the Home directory?
by Zuider 2y ago
Why did they remove tilde '~' as a convenient shortcut for the Home directory?
- bch 2y agoTcl Improvement Proposal (TIP) 602[0]. [0] https://core.tcl-lang.org/tips/doc/trunk/tip/602.md https://core.tcl-lang.org/tips/doc/trunk/tip/602.md
- throw0101b 2y agoOne example from the document: > Consider the naive attempt to clean out the /tmp directory. > cd /tmp > foreach f [glob *] {file delete -force $f} > A file ~ or ~user maliciously placed in /tmp will have rather unfortunate consequences.
- amelius 2y agoIsn't that just tilde-expansion happening at the wrong moment?
- em-bee 2y agoi once managed to create a directory named ~ using the mirror tool written in perl. then i naively tried to remove it using "rm -r ~" and started wondering why removing an empty directory would take so long, until it dawned on me... i learned a few new habits since then. i almost never use rm -r and i avoid "*" as a glob by itself. instead i always try to qualify "*" with a path, remove files first: "rm dir/*"; and then remove the empty directory. "rmdir dir/" if i do want to use rm -r, it is with a long path. eg in order remove stuff in the current directory i may distinctly add a path: rm -r ../currentdir/*" instead of "rm -r *" related, i also usually run "rm -i", but most importantly, i disable any alias that makes "rm -i" the default, because in order to override the -i you need to use -f, but "rm -i -f" i NOT the same thing as "rm". rm has three levels of safety: "rm -i; rm; rm -f". if "rm -i" is the default the "rm" level gets disabled, because "rm -i -f" is the same as "rm -f"
- kristopolous 2y agoI've long fantasized about a tool I call "expect" that safeguards against crazy stuff like that. It has a syntax of your expectations, functionally existing as a set of boundaries, and you can hook it to always run as a wrapper for some set of commands. It essentially stages the wrapped command and if none of the boundaries are violated it goes through. Otherwise it yells at you and you need to manually override it. For instance, pretend I'm ok with mv being able to clobber except in some special directory, let's call it .bitcoin or whatever. (chattr can also solve this, it's just an example). The tool can be implemented relying on things like bpf or preload Originally I wanted it as a SQL directive ... a way to safeguard a query against doing like `update table set field=value expect rows=1` where you meant to put in the where clause but instead blew away an entire column. I think this would be especially useful surfacing it in frameworks and ORMs some of which make these accidents a bit too easy.
- danielheath 2y agoFor sql specifically, “limit 2” is my default way to write “expect 1”; if it affects two rows, I know that I have screwed up, whereas “limit 1” can be wrong without my noticing.
- kristopolous 2y agoThat's not a terrible solution although expect sounds like a simple safety mechanism for feeble-minded people like me who do simple queries. I actually know postgres people. I should probably ask them
- kragen 2y agojust to clarify, this has nothing to do with the "expect" that is the other major application of tcl other than tk?
- kristopolous 2y agoNone. I was just reminded of a good idea I never implemented
- AlienRobot 2y agoI once created a file named *. Sweats were sweated that day.
- orthoxerox 2y agoI've heard that one of the Unix founding fathers had a directory with 125 files that all had single-byte names: one for each ASCII symbol except slash, dot and null. He would then test any new utility against this directory and chew the careless programmer out if it couldn't correctly handle every one of these names.
- cmacleod4 2y agoIn the long run, special cases like that often turn out to be more trouble than they are worth. If an ordinary file happened to start with '~' it would not be handled correctly. So you either accept or ignore that potential problem, or you have to write extra code to work around it. It's safer to not have such special cases at all.
- mirekrusin 2y agoShould be starts with ~/
- cmacleod4 2y agoNo, ~abc will be interpreted as the home directory of user abc in Tcl 8.*
- eviks 2y agoThen you fix this mistake, not remove ~ completely
- Y_Y 2y agoIt's not a mistake
- mirekrusin 2y agoIf it's not a mistake then why they took it off?
- cmacleod4 2y agoThe original design decision was to behave like a shell, where ~ means your own home dir and ~fred means fred's home dir. With the benefit of experience, this is now seen to be unwise and a different decision has been made.
- Koshkin 2y agoJust recently I used '~' in the remote target path in the scp command, and, somewhat unexpectedly, it created the directory with that name and put the files there.
- isr 2y agoIn 99% of cases, yes - this is a pain in the backside. Long ago I adopted something from the plan9 way of doing things (when I was heavily using acme). Just symlink /h to /home. So ~user becomes /h/user, in places where ~ is not expanded for you.