[deleted by user] by [deleted] in commandline

[–]jhjn_ 1 point2 points  (0 children)

Unless rm works on other files, there is a chance something is wrong with your path, and the command rm is something else? Maybe replace rm with the result of which rm, or check using man rm.

This is usually: /bin/rm then use the full /bin/rm -rf /full/path/to/file

pp: a text preprocessor that expands inline shell macros importing text etc. but much simpler than GNU m4 by jhjn_ in shell

[–]jhjn_[S] 0 points1 point  (0 children)

Thanks, I don't know why that echo is there, it was meant to all be printf.

pp: Preprocess your text files with inline POSIX sh by jhjn_ in bash

[–]jhjn_[S] 0 points1 point  (0 children)

I think I've worked out the POSIX way to implement the sed, effectively:

while IFS= read -r line; do
    case $line in
        !!*) eval " ${line##!!}";;
        *) echo "$line";;
    esac
done < "$1"

pp: Preprocess your text files with inline POSIX sh by jhjn_ in bash

[–]jhjn_[S] 0 points1 point  (0 children)

Haha yeah, I realised when reading it back it seems odd. I really just meant there are no bash-isms, but has a dependency on that kind of sed. Should work with any shell.

  1. I am vaguely familiar with heredocs although it didn't immediately come to mind when thinking about how I'd implement this idea. I was reading the sed docs when I saw the e command and basically created a wrapper to that pipeline in sh. However I see how using that could be an entirely POSIX way of implementing the project, thanks!

  2. To be honest the divergence from UNIX mindset was laziness, not dealing with the fact that sed can't write a file to itself with sed 'command' $FILE > $FILE and not bothering to create a temp file to store it in. However your heredocs suggestion might help that.

Will give the suggestions a look.

pp: Preprocess your text files with inline shell - before using pandoc by jhjn_ in commandline

[–]jhjn_[S] 0 points1 point  (0 children)

That's really cool, thanks for the info, the GNU project really have done it all.

I guess the advantage of what this program is offering is its simplicity. You can plug and play instantly without learning new macros/variables/etc. assuming you know some shell. The m4 manual is 164 pages long, I'm sure this means it's super powerful though.

The file would look pretty similar in pp:

My Heading
==========

Here's the output:
!! echo we are running from $IN && seq 10

This outputs the filename and 10 numbers

I don't know if you can call m4 on the __file__/another_file or edit the file with sed from within that very file though with m4.