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

Bug#969634: ITP: shellescape -- Escape arbitrary strings for use as command line arguments



On Sun, Sep 6, 2020 at 10:09 AM Jai Flack wrote:

>   Description     : Escape arbitrary strings for use as command line arguments

Generally this is the wrong approach and commands should be run
through fork+exec instead of escaping them and passing them through
the shell.

https://bonedaddy.net/pabs3/log/2014/02/17/pid-preservation-society/

>  escargs utility escargs reads lines from the standard input and prints
>  shell-escaped versions. Unlinke xargs, blank lines on the standard input are
>  not discarded.

There is already the shell-quote too from libstring-shellquote-perl in
Debian if you want something to run from an interactive shell.

Also xargs doesn't discard blank lines if you don't use the unsafe
variants of it. xargs without the -d or -0 options is unsafe.

$ (echo ; echo ; echo ) | xargs -n1 echo foo
foo
$ (echo ; echo ; echo ) | xargs -d '\n' -n1 echo foo
foo
foo
foo
$ printf '\0\0\0' | xargs -0 -n1 echo foo
foo
foo
foo

-- 
bye,
pabs

https://wiki.debian.org/PaulWise
https://bonedaddy.net/pabs3/


Reply to: