[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Editing Problem with bash script and sed

On Tue, Nov 14, 2017 at 07:37:34PM +0100, Thomas Schmitt wrote:
> Hi,
> after reading man 1 "read", i have to add option "-r" to my proposal:
>   ls -d * | grep "$1" | while read -r filename

That fixes one problem, but there are plenty more still unfixed.

If the user input ("$1") is to be treated as an ERE, then you could
do something like this:

for filename in *; do
    [[ $filename =~ $1 ]] || continue

But your grep is treating "$1" as a BRE, not an ERE, and bash doesn't
have any implementation of BREs.

In any case, I do NOT recommend writing your own script to replace and
augment rename(1).  Just run a bunch of rename commands from the shell
prompt to make the filenames look how you want them.

Reply to: