Le 02/10/2021 à 15:09, Greg Wooledge écrivait :
On Sat, Oct 02, 2021 at 01:41:35PM +0200, Léa Gris wrote:
$ declare -f hello

hello ()
{
     echo 'hello';
     echo 'world'
}

The issue is that in some circumstances, newline characters may be handled
as space, making the function declaration invalid.

Can you show an example where the output of declare -f is invalid?


hello (){ echo 'hello';echo 'world';}

LC_MESSAGES=C sudo bash -c "$(declare -f hello);hello"
hello
world

LC_MESSAGES=C sudo -i bash -c "$(declare -f hello);hello"
bash: -c: line 2: syntax error: unexpected end of file

Better illustrated how newlines are discarded:

$ sudo bash -c 'echo hello
echo world'
hello
world

$ sudo -i bash -c 'echo hello
echo world'
helloecho world

Or:

$ sudo bash -c "printf %q\\\n \"$(declare -f hello)\""
$'hello () \n{ \n    echo \'hello you  the\';\n    echo \'world\'\n}'

sudo -i bash -c "printf %q\\\n \"$(declare -f hello)\""
hello\ \(\)\ \{\ \ \ \ \ echo\ \'hello\ you\ \ the\'\;\ \ \ \ echo\ \'world\'\}




--
Léa Gris


Reply via email to