Printing a "Hello World" one-liner in bourne shell without directly using white space char

1

I'm currently trying to solve a tricky/silly challenge and i've come to a dead end.

The challenge is basically to form a one-liner /bin/sh compatible command line which essentially outputs "Hello World" without directly typing White space or Tab characters in the command itself.

for example something like -

echo Hello World

would be invalid since we used white space twice in the command line.

Any ideas?

Xeus

Posted 2015-01-28T14:48:47.953

Reputation: 11

Question was closed 2015-01-28T15:12:14.427

Welcome to PPCG! While this is probably a rare case which justifies a language-specific challenge (as it's trivial in many languages but particularly hard in sh), all challenges here need an objective winning criterion. If you get multiple correct answers, which one is the best? – Martin Ender – 2015-01-28T14:53:49.853

The most you can do is to use newlines between command and parameters: http://pastebin.com/DU5Gyde7 But this is not POSIX sh anymore.

– manatwork – 2015-01-28T14:54:26.263

@MartinBüttner, are you sure about the [tag:bash] tag? The question explicitly asks for “/bin/sh compatible”. – manatwork – 2015-01-28T14:56:08.090

@manatwork Whoops, good point. Changed to a new [tag:sh]. – Martin Ender – 2015-01-28T14:57:30.093

Answers

2

One which works in dash, so I suppose it is sh compatible;

IFS=@;command=echo@Hello@World;$command

manatwork

Posted 2015-01-28T14:48:47.953

Reputation: 17 865

1Yup@this@one@works!@great! – Xeus – 2015-01-28T15:00:58.980

2Or simply echo${IFS}Hello${IFS}World – jimmy23013 – 2015-01-28T18:01:45.703

1Yup, $IFS tricks are good. Here's another way for bash (but not Posix sh): a=({Hello,world});cat<<<${a[@]} – Digital Trauma – 2015-01-29T00:40:10.513

2@DigitalTrauma, actually {echo,Hello,world} is enough in bash and ksh. – manatwork – 2015-01-29T09:11:10.800

@manatwork Thats brilliant! – Digital Trauma – 2015-01-29T15:51:00.033