Labyrinth pattern

while ( true ) ; do if [ $(expr $RANDOM % 2 ) -eq 0 ] ; then echo -ne "\xE2\x95\xB1" ; else echo -ne "\xE2\x95\xB2" ; fi ; done
Generates labyrinth-like pattern on UTF-8 terminal in bash. For fun ;)
Sample Output
╲╲╲╱╱╲╲╱╲╲╲╱╲╲╲╲╲╲╱╲╱╲╱╱╲╱╱╱╲╱╱╱╲╲╲╲╱╲╱╱╱╱╲╱╲╲╱╱╲╲╲╱╱╲╱╲╲╱╲╱╱╲╱╲╱╲╲╲╱╲╲╱╲╲╱╱╱╲╱╲╲╲╱╲╲╲╲╲╲╱╱╲╱╱╱╲╲╱╲╲╱╲╱╱╱╱╲╱╱╱╱╲╲╲╱╲╲╱╲╱╱╲╱╲╱╲╱╲╲╲╲╲╱╲╱╲╲╲╲╲╲╲╱╲╲╱╲╲╱╱╱╲╱╱╲╱╲╱╱╱╲╲╲╲╲╲╱╱╲╱╱╲╲╱╲╲╲╲╱╱╱╱╲╲╱╱╱╲╱╱╱╱╲╲╲╲╲╲╲╲╱╲╱╱╲╱╲╲╱╱╱╲╲╲╱╲╲╱╱╲╲╲╱╲╲╱╱╱╱╱╲╱╱╲╱╲╱╱╱╱╱╲╲╲╲╱╱╱╲╱╲╲╱╱╲╱╲╲╲╲╲╲╱╱╱╲╲╲╱╲╲╲╱╲╲╱╱╱╲╱╱╲╱╱╱╲╱╲╲╱╱╲╱╲╲╲╲╱╲╲╱╲╱╱╲╱╲╱╲╲╲╲╱╲╱╲╲╲╱╱╱╲╲╲╲╱╲╱╲╲╱╲╲╲╲╱╲╲╲╱╲╱╲╱╱╲╲╱

2
By: tobi
2015-01-17 12:46:37

10 Alternatives + Submit Alt

What Others Think

The output's pretty, but the command could be improved. . First, let's swap (true) for : The colon operator is a null-operation (but it returns true). So this is common: while :; do COMMAND; done . Next, tidy the test condition and get rid of expr (an external command). Bash supports doing maths in $((...)) if [ $(($RANDOM % 2)) -eq 0 ]; then ... Personally, I'd change the "-eq 0" to "= 0" Yes, that's a string comparison, but it's nicer to read. . Next, replace the if statement with some boolean operators. '[' is a command in its own right: man test(1) If you've only got two one-command options, you can write: [ TEST-CONDITION ] && TRUE-COMMAND || FALSE-COMMAND . Combine all the above and you get: while :; do [ $(($RANDOM % 2)) = 0 ] && echo -ne "\xE2\x95\xB1" || echo -ne "\xE2\x95\xB2"; done . Because it only uses bash builtin commands it's much quicker, too.
flatcap · 175 weeks and 1 day ago
Hmm... I wasn't content with my previous answer. It's not 'fu' enough :-) The output is one of: echo -ne "\xE2\x95\xB1" echo -ne "\xE2\x95\xB2" . So I need to substitute a 1 or a 2 into an echo. . Adding 1 to the previous random number: echo $((RANDOM%2+1)) . And substitute for the test condition: while :; do echo -ne "\xE2\x95\xB$((RANDOM%2+1))"; done . Much nicer.
flatcap · 175 weeks and 1 day ago
Well, really fast!
tobi · 175 weeks and 1 day ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: