bug-bash
[Top][All Lists]
Advanced

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

Re: Request change to output of declare -f funcname


From: Léa Gris
Subject: Re: Request change to output of declare -f funcname
Date: Sat, 2 Oct 2021 18:06:32 +0200
User-agent: Telnet/1.0 [tlh] (PDP11/DEC)

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

[Prev in Thread] Current Thread [Next in Thread]