bug-bash
[Top][All Lists]
Advanced

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

Re: echo -n


From: Greg Wooledge
Subject: Re: echo -n
Date: Thu, 2 Feb 2017 12:10:29 -0500
User-agent: Mutt/1.4.2.3i

On Thu, Feb 02, 2017 at 10:26:22PM +0530, Jyoti B Tenginakai wrote:
> I have tried using the printf instead of echo. But the issue with printf
> is , the behaviour is not consistent with what echo prints for all the
> inputs i.e.

But what echo prints is by definition inconsistent across platforms and
shells and so on.

Make the code do what you want.  Do not attempt to make it use a broken
command in some consistent way.

> In my script I am generically using echo for all the options.

Why?  What do you want to write to stdout?  Figure out what you want to
do, then do it.

> If I have to
> use printf instead of it should behave consistently .

printf behaves consistently.

> if echo * is passed to bash shell

... what does that mean?  Your user is passing a quoted string 'echo *'
as an argument?  What are you doing, eval'ing user arguments as shell
commands?

Or do you mean that you have the command   echo *   in your script?

What do you WANT it to do?

Do you want it to print the files in $PWD one per line?  Blithely ignoring
the possibility of filenames that contain newlines?

printf '%s\n' *

That will print each filename (except dot files, but your original command
has the same issue) with a newline after it.

If a filename contains a newline, then there will be two newlines
produced for that particular filename: the one inside it, and the one
added by the printf format spec.

> the o/p shows the \t seperated values

The who what?  What the hell are you talking about now?

> whereas with printf '%s'  *, it won't display space separated output.

You want SPACES now?

printf '%s ' *

> Again
> printf '%s ' # behaviour is different from what echo # shows

Are you talking aobut the one trailing space that you'll get from

printf '%s ' *

vs.

echo *

??

Do you actually CARE about ONE SPACE?

Do you have an actual GOAL here?  Or are you just flailing around
randomly until you stumble across some way to bitch about printf?

I really hate it when people have a desired answer and then keep
flailing around at the English language until they come up with a
question that they think will give them their desired answer.

In your case, your desired answer is apparently "to run the command echo *".

Nobody can possibly satisfy your demands, because you don't have a goal.



reply via email to

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