globalcitizen / taoup

The Tao of Unix Programming (Ruby-powered ANSI colored fortunes)
GNU General Public License v3.0
414 stars 20 forks source link

shuf never used in taoup-fortune #26

Closed minhtrancccp closed 7 months ago

minhtrancccp commented 7 months ago

when i checked whether shuf was installed on my machine with type shuf or which shuf, both of them confirmed that shuf is /usr/bin/shuf.

but as this log below showed what i observed as i executed bash -x taoup-fortune 2>&1, the program seemed to assume that shuf was unavailable.

++ dirname taoup-fortune
+ dir=.
++ which md5sum
+ '[' /usr/bin/md5sum ']'
++ md5sum ./taoup
++ cut -d ' ' -f1
+ MD5SUM=260d2085d6fdc421c1faf9505dcf2898
+ cachefile=./.taoup-fortune.cache.260d2085d6fdc421c1faf9505dcf2898
+ '[' '!' -r ./.taoup-fortune.cache.260d2085d6fdc421c1faf9505dcf2898 ']'
++ which cowsay
+ '[' /usr/bin/cowsay ']'
++ shuf -e
+ '[' ']'
++ echo test
++ sort -R
+ '[' test ']'
+ cat ./.taoup-fortune.cache.260d2085d6fdc421c1faf9505dcf2898
+ grep -v '^---'
+ sort -R
+ head -n 1
+ cowsay -f eyes -n
+ head -n 2
+ tail -n 1
< Between Plan 9 and Erlang we missed a bus somewhere. - @jacquesm >
+ echo ''
+ cowsay -f eyes
+ tail -n 10
+ sed 's/^//'
     \
                                   .::!!!!!!!:.
  .!!!!!:.                        .:!!!!!!!!!!!!
  ~~~~!!!!!!.                 .:!!!!!!!!!UWWW$$$ 
      :$$NWX!!:           .:!!!!!!XUWW$$$$$$$$$P 
      $$$$$##WX!:      .<!!!!UW$$$$"  $$$$$$$$# 
      $$$$$  $$$UX   :!!UW$$$$$$$$$   4$$$$$* 
      ^$$$B  $$$$\     $$$$$$$$$$$$   d$$R" 
        "*$bd$$$$      '*$$$$$$$$$$$o+#" 
             """"          """"""" 
+ echo '(B'
(B

apparently the test for shuf's functionality in the program is by testing whether shuf -e 2>/dev/null doesn't return a null string, which it would as no strings or files were passed into the command.

even if the test was to verify whether -e was a valid option for the machine's shuf, that would be redundant as -e was implemented in the first public version of shuf, per the git history of the program in coreutils.

a solution could be to adapt the test for cowsay's existence to shuf, such as which shuf 2>/dev/null.

globalcitizen commented 7 months ago

Aha, nice find! Thanks.

globalcitizen commented 7 months ago

Should be resolved in https://github.com/globalcitizen/taoup/commit/affd9fe6dba62031f964078dff6d9c9e2f8ce079

globalcitizen commented 7 months ago

Released as https://github.com/globalcitizen/taoup/releases/tag/v1.1.23