Discussion:
[Help-bash] How to prevent parameters being interpreted in pipe?
Patrick Schleizer
2016-12-04 19:55:00 UTC
Permalink
Hi,

code talks. :)

works:
echo "test" | base64 -d

works:
echo "--INVALID something" | grep thing

Let's assume the input would be different.

does not work:
echo "-e test" | base64 -d

Why works base64 different?

How to prevent interpreting "-e" as parameter? I.e. how to have it
interpreter as string?

Cheers,
Patrick
Matthew Cengia
2016-12-05 01:53:15 UTC
Permalink
Don't use echo; use printf with -- as an argument:

printf -- '%s\n" "-e test"

On Mon, Dec 5, 2016 at 6:55 AM, Patrick Schleizer <
Post by Patrick Schleizer
Hi,
code talks. :)
echo "test" | base64 -d
echo "--INVALID something" | grep thing
Let's assume the input would be different.
echo "-e test" | base64 -d
Why works base64 different?
How to prevent interpreting "-e" as parameter? I.e. how to have it
interpreter as string?
Cheers,
Patrick
--
Regards,
Matthew Cengia
konsolebox
2016-12-05 06:57:09 UTC
Permalink
Post by Matthew Cengia
printf -- '%s\n" "-e test"
I don't see '--' necessary.
--
konsolebox
Patrick Schleizer
2016-12-05 12:57:00 UTC
Permalink
That doesn't work either.

printf -- "%s\n" "-e test" | base64 -d
base64: invalid input
Post by Matthew Cengia
printf -- '%s\n" "-e test"
On Mon, Dec 5, 2016 at 6:55 AM, Patrick Schleizer <
Post by Patrick Schleizer
Hi,
code talks. :)
echo "test" | base64 -d
echo "--INVALID something" | grep thing
Let's assume the input would be different.
echo "-e test" | base64 -d
Why works base64 different?
How to prevent interpreting "-e" as parameter? I.e. how to have it
interpreter as string?
Cheers,
Patrick
John McKown
2016-12-05 13:49:48 UTC
Permalink
On Mon, Dec 5, 2016 at 6:57 AM, Patrick Schleizer <
Post by Patrick Schleizer
That doesn't work either.
printf -- "%s\n" "-e test" | base64 -d
base64: invalid input
The message seems reasonable to me.​

​The string "-e test" is not valid base64 encoded data. The "base64 -d"
says to decode base64 input back into a "normal" string.

Transcript:

[~]$ printf -- "%s\n" "-e test" | base64 -d
base64: invalid input
[~]$ printf -- "%s\n" "-e test"
-e test
[~]$ printf -- "%s\n" "-e test" | base64
LWUgdGVzdAo=
[~]$ printf -- "%s\n" "-e test" | base64 | base64 -d
-e test
[~]$
--
Heisenberg may have been here.

Unicode: http://xkcd.com/1726/

Maranatha! <><
John McKown
Loading...