The time now is Fri 26 Feb 2021, 23:14
All times are UTC - 4 |
Author |
Message |
puppy_apprentice

Joined: 07 Feb 2012 Posts: 300
|
Posted: Wed 21 Nov 2018, 19:11 Post subject:
|
|
musher0 this code you can use in your scripts:
Code: | #!/bin/sh
colors=$(echo -e "34\n35\n36\n37"); colmatrix=($colors); r=$((RANDOM%4)); echo -e "\e[${colmatrix[$r]}m Hello World! \e[0m" |
Description |
Immortal "Hello Worlds!" in 4 ANSI colors |
Filesize |
46.9 KB |
Viewed |
264 Time(s) |

|
|
Back to top
|
|
 |
musher0
Joined: 04 Jan 2009 Posts: 15041 Location: Gatineau (Qc), Canada
|
Posted: Wed 21 Nov 2018, 19:59 Post subject:
|
|
@puppy_apprentice:
Your modesty is quite to be commended. But judging by your recent output,
I'd say that you're well on your way of surpassing at least this supposed
"Bash magic" master... (I.e. me.)
That's fine, and please go for it! I have serious reservations about the
traditional concept of "competition", but I'm all for "emulation".
My best wishes to you in this!
BFN.
_________________ musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
|
Back to top
|
|
 |
puppy_apprentice

Joined: 07 Feb 2012 Posts: 300
|
Posted: Wed 21 Nov 2018, 20:11 Post subject:
|
|
I was thinking about your ThisWeek.sh script in wich you use ANSI codes.
Ok. I have some experience with other programming languages but i'm not fluent in any.
I think that for example i won't write this kind of sed game:
https://aurelio.net/projects/sedsokoban/
Have a nice day/evening all.
|
Back to top
|
|
 |
musher0
Joined: 04 Jan 2009 Posts: 15041 Location: Gatineau (Qc), Canada
|
Posted: Wed 21 Nov 2018, 21:05 Post subject:
|
|
Thanks for the feedback, puppy_apprentice.
~~~~~~~~~~~
@all:
If anyone is interested, I have made available the latest version of
coreutils, version 8-30, for PuppyLinux, here.
To anyone wondering: the link with this thread is that the GNU coreutilis
contain, among many others, three utilities used in various scripts in this
thread: cal (the full version), date and nl.
BFN.
_________________ musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
|
Back to top
|
|
 |
musher0
Joined: 04 Jan 2009 Posts: 15041 Location: Gatineau (Qc), Canada
|
Posted: Thu 22 Nov 2018, 04:18 Post subject:
|
|
Hello all.
In lieu of < nl > to number lines, one can use < cat -n >: Code: | >echo;cal | grep -v [[:alpha:]] | cat -n | grep --color=always "$(date '+%d')" |
Also possible for this is the use of < grep -n >, as mentioned somewhere
above by puppy_apprentice IIRC: Code: | echo;cal | grep -v [[:alpha:]] | grep -n --color=always "$(date '+%d')" | tr ":" "\t";echo -e "\e[1A\e[1Cth wk:" | This is completed by a replacement, through < tr >, of the colon by a tab,
and then we insert for information the string "th wk:" between the week
number and the line of dates, through a couple of ANSI escape codes.
We can decorate it like so: Code: | echo;echo -e "\t \e[33m\e[4m`date '+%b %Y'`\e[0m";cal | grep -v [[:alpha:]] | grep -n --color=always "$(date '+%d')" | tr ":" "\t";echo -e "\e[1A\e[1Cth wk:";echo -e "\t\e[33m`cal | grep -v [[:digit:]]`\e[0m" | Scrot attached.
BFN.
Description |
|
Filesize |
23.91 KB |
Viewed |
232 Time(s) |

|
_________________ musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
|
Back to top
|
|
 |
fredx181

Joined: 11 Dec 2013 Posts: 4481 Location: holland
|
Posted: Thu 22 Nov 2018, 05:16 Post subject:
|
|
musher0 wrote: | If anyone is interested, I have made available the latest version of
coreutils, version 8-30, for PuppyLinux, here.
To anyone wondering: the link with this thread is that the GNU coreutilis
contain, among many others, three utilities used in various scripts in this
thread: cal (the full version), date and nl. |
Hi musher0, I couldn't find 'cal' in your pet.
On my Debian stretch system none of codes here work unless I change 'cal' to 'busybox cal' (not a problem, btw, just curious about 'cal (the full version)'.
(on my system /usr/bin/cal is symlink to /usr/bin/ncal part of package bsdmainutils)
Fred
_________________ Dog Linux website
Tinylinux blog by wiak
|
Back to top
|
|
 |
musher0
Joined: 04 Jan 2009 Posts: 15041 Location: Gatineau (Qc), Canada
|
Posted: Thu 22 Nov 2018, 08:48 Post subject:
|
|
fredx181 wrote: | musher0 wrote: | If anyone is interested, I have made available the latest version of
coreutils, version 8-30, for PuppyLinux, here.
To anyone wondering: the link with this thread is that the GNU coreutilis
contain, among many others, three utilities used in various scripts in this
thread: cal (the full version), date and nl. |
Hi musher0, I couldn't find 'cal' in your pet.
On my Debian stretch system none of codes here work unless I change 'cal' to 'busybox cal' (not a problem, btw, just curious about 'cal (the full version)'.
(on my system /usr/bin/cal is symlink to /usr/bin/ncal part of package bsdmainutils)
Fred | By golly, you're right, Fred.
I mistook cat for cal...
Sorry about that. (Note to myself : must get new glasses...)
Back hunting. TWYL.
~~~~~~~~~~~
Edit, 5 minutes later --
cal is part if the utils-linux package, whose latest source is here.
Edit, an hour later --
I have compiled the latest utils-linux package, version 2.33, for
PuppyLinux. It is available through here.
Again thanks to Fredx181 for having a falcon's eye.
BFN.
_________________ musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
|
Back to top
|
|
 |
MochiMoppel

Joined: 26 Jan 2011 Posts: 2084 Location: Japan
|
Posted: Thu 22 Nov 2018, 10:47 Post subject:
|
|
musher0 wrote: | Also possible for this is the use of < grep -n >, as mentioned somewhere
above by puppy_apprentice IIRC: Code: | echo;cal | grep -v [[:alpha:]] | grep -n --color=always "$(date '+%d')" | tr ":" "\t";echo -e "\e[1A\e[1Cth wk:" |
|
There is more to learn from puppy_apprentice's code:
Reread how he fixed the date command to prepare for single digit dates and how he uses the -w option for the grep command, a clever trick. On the first day of the month grep will match only '1' but not '10' or '21'
|
Back to top
|
|
 |
musher0
Joined: 04 Jan 2009 Posts: 15041 Location: Gatineau (Qc), Canada
|
Posted: Thu 22 Nov 2018, 14:05 Post subject:
|
|
Hi, MM.
I'm sure. But not now, please.
Back later.
_________________ musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
|
Back to top
|
|
 |
fredx181

Joined: 11 Dec 2013 Posts: 4481 Location: holland
|
Posted: Thu 22 Nov 2018, 15:27 Post subject:
|
|
musher0 wrote: | I have compiled the latest utils-linux package, version 2.33, for
PuppyLinux. It is available through here. |
Thanks, the cal included works fine for me.
P.S. see screenshot , running just cal, note that 'busybox cal' is not translated, cal from utils-linux and ncal are in Dutch, as my system locale is set (and ncal looks very different)
(and translated, the week goes from monday to sunday)
Fred
Description |
Different cal's |
Filesize |
79.24 KB |
Viewed |
147 Time(s) |

|
_________________ Dog Linux website
Tinylinux blog by wiak
|
Back to top
|
|
 |
musher0
Joined: 04 Jan 2009 Posts: 15041 Location: Gatineau (Qc), Canada
|
Posted: Thu 22 Nov 2018, 15:34 Post subject:
|
|
@fredx181:
With the "real" < cal >, you have to say < cal -s > for the week to start
on Sunday.
_________________ musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
|
Back to top
|
|
 |
musher0
Joined: 04 Jan 2009 Posts: 15041 Location: Gatineau (Qc), Canada
|
Posted: Thu 22 Nov 2018, 16:39 Post subject:
|
|
@MochiMoppei and puppy_apprentice:
I studied it, but I really do not understand the random color part in
puppy_apprentice's script. Worse: I do not understand the need for it!
In particular, the part X1X2, etc. and the line of dates. How do you get
that XIX2, etc. part to appear? In an hex editor? I could not reproduce
it by any means I know.
Sorry.
~~~~~~~~~~
I did catch the need for < grep -wn $(date '+%d'>, however; not just
< grep -n >.
And MM, any reason why your syntax is different than mine for
< date '+%d' >? They give the same result.
BFN.
_________________ musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
|
Back to top
|
|
 |
fredx181

Joined: 11 Dec 2013 Posts: 4481 Location: holland
|
Posted: Thu 22 Nov 2018, 17:13 Post subject:
|
|
musher0 wrote: | @fredx181:
With the "real" < cal >, you have to say < cal -s > for the week to start
on Sunday. |
Ah, ok, btw for me with LANG=en_US the week starts automatically on Sunday without the -s switch :
Code: | root@live:~# LANG=en_US cal # full cal
November 2018
Su Mo Tu We Th Fr Sa
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 |
So somehow it seems to detect which locale.
Fred
_________________ Dog Linux website
Tinylinux blog by wiak
|
Back to top
|
|
 |
musher0
Joined: 04 Jan 2009 Posts: 15041 Location: Gatineau (Qc), Canada
|
Posted: Thu 22 Nov 2018, 18:00 Post subject:
|
|
Hi Fred.
Thanks for the feedback.
The authors must've improved it. In older versions that I've used, the -s
was needed if you wanted the week to start on Sunday.
As well, you may have noticed that the real cal highlights today's date,
whereas the busybox cal does not.
BFN.
_________________ musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
|
Back to top
|
|
 |
MochiMoppel

Joined: 26 Jan 2011 Posts: 2084 Location: Japan
|
Posted: Thu 22 Nov 2018, 19:32 Post subject:
|
|
musher0 wrote: | And MM, any reason why your syntax is different than mine for
< date '+%d' >? They give the same result. | Exactly which syntax are you referring to?
|
Back to top
|
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|