Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore -R flag #9

Closed
SkycoinSynth opened this issue Feb 25, 2021 · 4 comments
Closed

Restore -R flag #9

SkycoinSynth opened this issue Feb 25, 2021 · 4 comments

Comments

@SkycoinSynth
Copy link

rpl -R is a standard unix/linux command that has been in use for forty years. And it is the best way to find and replace strings without using regular expressions.

And handles files with spaces in the name unlike xargs, which requires esoteric command line arguments to work for all file names and escaped characters.

The -R flag should only be removed if you hate linux and want it to die.

@rrthomas
Copy link
Owner

Thanks for your bug report!

The first version of rpl was written in 1998, as far as I can tell, though I'm sure similar utilities have existed for much longer; indeed, it's a mystery to me why there isn't a standard Unix tool for this task! I wrote a similar program, though much less capable, starting from 2006.

Note that by default rpl 1.8 and later does use regular expressions, though you can use the -F flag to prevent this. I changed the behaviour because most similar tools (most obviously grep) interpret the pattern you give them as a regex by default.

There's nothing esoteric about getting find and xargs to work with all filenames:

find PATH [PREDICATES] -print0 | xargs -0 [COMMAND]

It's a shame in one sense that this is not the default behaviour. But on the other, if you just do:

find . | xargs rpl OLD NEW

this will work for all filenames that don't contain a newline.

I recently discovered that you don't need xargs; you can say:

find . -exec rpl OLD NEW {} +

It turns out that + is a standard feature and has been for many years; it's just not widely known.

However, rpl 1.8 no longer needs this; you can use recursive globbing with **:

rpl OLD NEW '**/*'

I will not be restoring -R. Closing.

@SkycoinSynth
Copy link
Author

SkycoinSynth commented Feb 25, 2021

Why are you forking rpl so that it is no longer comparable with the BSD distribution rpl and the rpl distributed by all other linux distributions?

This is clearly a standards and compatibility problem.

Why are you biased against maintaining the standard behavior of this command, as documented in all linux/unix man pages for decades?

How does removing functionality improve linux?

How does removing a documented feature in the man page, help the linux community?

Why were you given maintainer status by debian?


Also

  • rpl -R "old" "new" .
  • find . | xargs rpl "old" "new"

Which one of these two commands is easier to read and more clear?

This is clearly a usability issue. The only purpose of rpl is for finding and replacing text, for simple cases that do not require regex.

Should the -R flag be removed from grep? Shall I ask the grep maintainer if he agrees with your argument?

Should the -R flag be removed from rm because its "too dangerous"?


Also, you can do

rpl old new `find . `

and it is cleaner because you do not have to use xargs. But again, your solution is highly discriminatory and
racist against non-english speaking peoples. It is only suitable for english language and for file names that do not contain space and escaped characters. And it discriminates against simple, universal, accessible linux commands.

If you remove the -R command line flag, you are going to be driving people to use perl and awks for operations that do not require it.

@SkycoinSynth
Copy link
Author

I would suggest you maintain the standard behavior of rpl, so that it matches BSD and all other linux distributions. For comparability and standardization between linux distributions.

And also for improved readability.

rpl -R "old" "new" .

As one of these is clearly cleaner and more readable than the other.

find . | xargs rpl "old" "new"

Then make a branch of rpl called "rpl-lite" with the features you do not like removed. And see if your neutered and featureless version of rpl becomes wildly popular.

And maybe have "grep-lite" with -R removed.

And "rm-safe" with -R removed for safety.

And so on and we can gradually remove the -R flag from the most popular linux command line utilities to drive people into using perl, xargs and ack and replacing simple one line commands with complex shell scripting.

@rrthomas
Copy link
Owner

I haven't forked rpl, I took over this version. (There is also the original non-free version.) rpl is not standardized. I was not given maintainer status by Debian; the Debian maintainer chose to use my package.

grep has a -R and/or -r flag in many implementations, but they are not in fact part of the standard (see man 1posix grep).

grep is read-only, so the only problem with using grep -R is that you get results you don't want. rm -r is simple: it removes all files. rpl -R is confusing: it can edit files that you don't want edited, for example under .git.

My suggested solutions (in particular, using rpl with globs) work with files that contain spaces and punctuation.

It is indeed simpler to combine Unix tools (as the designers of Unix intended), than to keep adding new options to programs. find and xargs are standard tools which have existed since long before rpl, and it's well worth learning how to use them!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants