News for hackers. Stuff that matters.
Re:Detecting the use of “curl – bash” server side (2016) by lqet on Wednesday December 09, 2020 @05:11AM (#25357085)
> This allows constructing pipelines that read from and write to the same file.

TIL, how did I not know about sponge before?

Re:Detecting the use of “curl – bash” server side (2016) by OskarS on Wednesday December 09, 2020 @05:17AM (#25357121)
sponge rules, but you need to be careful. Lets say you wanted to search/replace a file with sed and sponge, then this does not work:

   cat file.txt | sed "s/a/b/g" | sponge > file.txt
Because bash opens file.txt for writing and truncates it immediately, so "cat file.txt" wont output anything. You have to do this for it to work:

   cat file.txt | sed "s/a/b/g" | sponge file.txt
sponge wont open the file for writing until it's sponged everything up. If you remember this, sponge is an awesome tool in the UNIX toolbox.
Re:Detecting the use of “curl – bash” server side (2016) by bonoboTP on Wednesday December 09, 2020 @06:25AM (#25357516)
Of course with sed you'd use the -i flag.
Re:Detecting the use of “curl – bash” server side (2016) by jniedrauer on Wednesday December 09, 2020 @10:34AM (#25359567)
Unless you're on MacOS, in which case it's -i''. I always have to rewrite cross platform scripts at least once.
Re:Detecting the use of “curl – bash” server side (2016) by dwheeler on Wednesday December 09, 2020 @12:27PM (#25361073)
Right. The sed -i option is incompatible between MacOS & Linux, and it isn't in the POSIX standard. The POSIX folks don't want to add it because it's possible to do work without it, even though no one wants to. Maybe sponge should be in the POSIX standard.
Re:Detecting the use of “curl – bash” server side (2016) by waynesonfire on Wednesday December 09, 2020 @05:51PM (#25366454)
I ran into this on FreeBSD. I do have gnu sed and other gnu utilities installed on my Mac to help me feel more at home.
Re:Detecting the use of “curl – bash” server side (2016) by knome on Wednesday December 09, 2020 @11:44AM (#25360552)
This doesn't seem to have any real advantage over just using an intermediate file.
Re:Detecting the use of “curl – bash” server side (2016) by OskarS on Wednesday December 09, 2020 @12:41PM (#25361255)
Of course you can always use an intermediate file, the point is that sponge is a very convenient way to just do it in a single command, without having to use intermediate files.

You don't have to use pipes either, you know. You can just save the output from every command to an intermediate file, then run the next command with that file as input.

Re:Detecting the use of “curl – bash” server side (2016) by steerablesafe on Wednesday December 09, 2020 @05:18AM (#25357132)
Check out the other moreutils utilities as well, it's a gem. vidir is especially useful with vim, but you can use it with any other text editor.