Re: how to (safely) escape an arbitrary string for use in PS1
From:
Christoph Anton Mitterer
Subject:
Re: how to (safely) escape an arbitrary string for use in PS1
Date:
Tue, 25 May 2021 04:27:59 +0200
User-agent:
Evolution 3.38.3-1
On Mon, 2021-05-24 at 11:48 +0900, Koichi Murase wrote:
> Yeah. To use local variables, I think currently we need to define a
> function inside the sourced files
...
> Or we source the file in a function:
But both would just kinda shift the problem: then I'd overwrite a
possibly existing function name.
> > [ -n "${str##*[\$\`\'\"\\]*}" -o -z "${str}" ] && echo "NO evil
> > char" || echo "evil char"
> > or
> > [ -n "${str##*["$`'\"\\"]*}" -o -z "${str}" ] && echo "NO evil
> > char" || echo "evil char"
>
> $ case $str in *[\$\`\'\"\\]*) echo "NO evil char" ;; *) echo "evil
> char" ;; esac
>
> is the POSIX way.
But case has the problem that it's affected by nocasematch, while
${var##...} doesn't seem to be.
Which is of course no problem in this specific matching case.
> Also, "-o" is obsoleted in POSIX.
Interesting... I've never made it down to the rational section of test
and till now never really thought about the issues with -a and -o.
They should probably put a bigger warning at the main section of the
documentation.
Guess that's why bash doesn't even mention these operators nor ( ) in
test?
Thanks,
Chris.