Upgrade to Pro — share decks privately, control downloads, hide ads and more …

思わぬ動きをするコマンドの事例

 思わぬ動きをするコマンドの事例

致命的バグヤロ!?という枯れているはずのコマンド事例

papiron

June 18, 2016
Tweet

More Decks by papiron

Other Decks in Programming

Transcript

  1. ෆਖ਼ͳ೔෇ͷݕূ ෆਖ਼ͳ೔෇Λࢦఆ͢ΔͱΤϥʔ͕ൃੜ $ date -j -f '%Y%m%d' 20160150 '+%Y೥%m݄%d೔' Failed

    conversion of ``20160150'' using format ``%Y%m%d'' $ date -j -f '%Y%m%d' 20160150 '+%Y೥%m݄%d೔' Failed conversion of ``20160150'' using format ``%Y%m%d'' 2016೥1݄50೔ 2016೥13݄1೔
  2. ෆਖ਼ͳ೔෇ͷݕূ Τϥʔ͕ൃੜͯ͠ͳ͍ʂʁʂʁ දࣔ͞Εͨ೔෇͕͓͔͍͠ʁʁ $ date -j -f '%Y%m%d' 20160200 '+%Y೥%m݄%d೔'

    2016೥01݄31೔ $ date -j -f '%Y%m%d' 20150229 '+%Y೥%m݄%d೔' 2015೥03݄01೔ 2016೥2݄0೔ 2015೥2݄29೔
  3. ෆਖ਼ͳ೔෇ͷݕূ GNU൛ͷdateίϚϯυͰ͸Τϥʔൃੜ $ gdate -d '20160200' '+%Y೥%m݄%d೔' gdate: invalid date

    ‘20160200’ $ gdate -d '20150229' '+%Y೥%m݄%d೔' gdate: invalid date ‘20150229’ 2016೥2݄0೔ 2015೥2݄29೔
  4. ݁࿦ʂʁ • dateίϚϯυͰ೔෇ͷݕূ • GNU൛date • ෆਖ਼ͳ೔෇͸Τϥʔൃੜ • BSD൛date •

    Ұ෦ͷෆਖ਼ͳ೔෇ͰΤϥʔ͕ൃੜ͠ͳ͍ • ͜Ε͸க໋తόάͰ͸ͳ͍ͷ͔ʁʁ
  5. ͲΜͳཚ਺͕ൃੜʁ ϚχϡΞϧʹΑΔͱ0͔Β1ͷؒͷ਺஋ • Macඪ४awk • rand random number on (0,1)

    • GNU൛awk • rand() Return a random number N, between 0 and 1, such that 0 <= N < 1. • mawk • rand() Returns a random number between zero and one. ֤छAWKͷਖ਼ࣜϚχϡΞϧΑΓ
  6. awkͰཚ਺ൃੜͷ۩ମྫ $ yes | awk 'BEGIN{srand()}{print rand()}' 0.468882 0.800048 0.259498

    0.369426 0.88324 ... yesίϚϯυͱawkͷ࿈ܞͰແݶʹཚ਺Λൃੜ
  7. awkͰཚ਺ൃੜͷ۩ମྫ $ yes | awk 'BEGIN{srand()}{print rand()}’ ɹ| head -n

    100 ཚ਺Λ100ݸൃੜͤ͞Δ৔߹͸ԼهͷΑ͏ʹɻ $ seq 100 | awk 'BEGIN{srand()}{print rand()}’ headίϚϯυͰ࠷ޙʹ100ߦ෼੾Δ seqίϚϯυͰ100ߦੜ੒
  8. ࠷େ࠷খ஋ͷ֬ೝํ๏ $ yes | awk 'BEGIN{srand()}{print rand()}' | head -n

    100 | sort -n 0.0059382 0.0111584 ... 0.995792 0.999588 sortίϚϯυͷ-nΦϓγϣϯͰ਺஋ॱʹฒ΂ସ͑Δ
  9. ิ଍ $ yes | awk 'BEGIN{srand()}{print rand()}' | head -n

    100 | st --min --max min max 0.0248714 0.999223 stίϚϯυͱ͍͏ศརͳίϚϯυ΋͋Δ ฏۉ஋ɺதԝ஋ɺඪ४ภࠩͳͲ΋ܭࢉՄೳ stίϚϯυͷGithubαΠτ͸ͪ͜Β https://github.com/nferraz/st
  10. ิ଍ $ yes | gawk 'BEGIN{srand()}{print rand()}' | head -n

    100 | awk ‘BEGIN{min=10000;max=-10000} {if($1<min){min=$1};if($1>max){max=$1}} END{print min,max}’ 0.00555304 0.996305 awkͰ΋֬ೝ͸Մೳ
  11. ཚ਺ੜ੒ςετ $ yes | awk 'BEGIN{srand()}{print rand()}' | head -n

    100 | sort -n | sed -n ‘1p;$p’ | xargs 0.0114521 0.991685 Macඪ४awk 0͔Β1ͷൣғ
  12. ཚ਺ੜ੒ςετ $ yes | gawk 'BEGIN{srand()}{print rand()}' | head -n

    100 | sort -n | sed -n ‘1p;$p’ | xargs 0.0114521 0.991685 GNU൛awk 0͔Β1ͷൣғ
  13. ཚ਺ੜ੒ςετ $ yes | mawk 'BEGIN{srand()}{print rand()}' | head -n

    100 | sort -n | sed -n ‘1p;$p' | xargs 0.0307588 1.99062 mawk 0͔Β1ͷൣғ͡Όͳ͍ʁʁ 0͔Β2ͷൣғͬΆ͍ʁʁ
  14. ཚ਺ੜ੒ςετ $ yes | mawk 'BEGIN{srand()}{print rand()}' | head -n

    100 | sort -n | sed -n ‘1p;$p’ | xargs 0.00340401 0.981487 mawk ઌͷ࣮ݧྫ͸MacͰ࣮ߦ ࠓ౓͸LinuxͰ࣮ߦͯ͠ΈΔͱʁ 0͔Β1ͷൣғ
  15. ݪҼ͸ʁ $ yes | ./mawk 'BEGIN{srand()}{print rand()}' | head -n

    100 | sort -n | sed -n '1p;$p' | xargs 0.00650974 0.987933 mawk 0͔Β1ʹͳͬͨʂʂ patch͋ͯͨmawkͰ࣮ݧʂ