Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

シェル芸でライフハック(特論)

364 views

Published on

所属サークルで行ったシェル芸特論のスライドです。
実演部分は略していますが、例題の答を解析するだけでも十分シェルの勉強になると思います。

Published in: Technology
  • Be the first to comment

  • Be the first to like this

シェル芸でライフハック(特論)

  1. 1. — :(){:|:&};: —
  2. 2. • Twitter @obknnt • ※TL Twitter • http://blueeyes.sakura.ne.jp/ • • • Vim Vim Vim • EMACS Makes Any Computer Slow * • Sublime Text • Emacs Atom $ whoami
  3. 3. • PSoC ( ) • CPLD with ARM • MSP430 (Texas Instruments) • RX Mac or Linux • I2CLCD • GCC Mac
  4. 4. Index • • • • • • • • • • •
  5. 5. • • • • QoL • Micr○ $○ft • • ※
  6. 6.
  7. 7. • GUI CLI • gcc echo gcc -xc - ( ) • • OK
  8. 8. OS: macOS Sierra (MacBook Air Early 2014) Terminal: iTerm2 Shell: Zsh 5.4.1 with GNU coreutils : https://github.com/shima-529/ dotfiles/ ※ Windows 10 Bash on Ubuntu on Windows ( )
  9. 9. • • - echo • - python • - bc • - sed, tr • - factor • - awk, perl • …
  10. 10. • (standard I/O) • C stdio.h • (stderr) • • | (Shift + ) • • • 1 ( n) •
  11. 11. 1. 1 100 2. file00 file99 .yjsnpi 3. 5, 6, 3, 10, 1 4. 1, 5, 3, 6, 9, 0, 1, 4, 2, 5 5. ( ) 6. 1 100000 1
  12. 12. 7. hoge() main #include <stdio.h> #include <string.h> int main(void){ hoge("NULL"); return 0; } void hoge(const char *str) { if( strcmp(str, "NULL") == 0 ) { printf("NULL NULL n"); }else{ for(int i=0; i<strlen(str); i++) { printf("%c ", str[i]); } } }
  13. 13. 8. echo ( ) 

  14. 14. 1. seq 1 100 | factor | awk 'NF==2{print $2}' | xargs 2. touch file{00..99};
 find . | xargs -n1 basename | sed -n 's/^.*$/mv & &.yjsnpi/e' 3. cat graph | awk '{printf $0 ": ";for(i=0; i<$0; i++){printf "*"}printf "n"}' 4. echo "1n5n3n6n9n0n1n4n2n5" | sort -n | uniq -d 5. seq 1 $(tput cols) | awk '{a=22*(1+sin($1/30));system(sprintf("tput cup %d %d", a, $1-1));printf "*"} END{system("clear;sleep 1")}' 6. seq 1 100000 | shuf >data # 
 cat data | sort -nr #
  15. 15. 7. sed '/main/,/^}/{H;d};$G' hoge.c
 Vim ※ 
 vim -es hoge.c +':norm gg}d}Gp' +%p +q! 8. echo | sed -r -ne'p;s/(.)(.*)/ 21/#'{1..10} ド ※) Vim vimshell (https://togetter.com/li/1080646)
  16. 16. (1) • grep: • grep -o: • grep -o . : • xargs: • eval: • sort: • uniq: 1 • seq: seq inf • yes: • yes : • yes 5 :
  17. 17. (2) • cat: • tac: • rev: • paste: • openssl prime: 10 • openssl prime -hex: 16 (0x ) • factor: 10 • nkf: • wc: ( n ) • wc -l : • wc -c : • base64: == • file - :
  18. 18. • • Excel • Excel • gnuplot • csv LaTeX • LaTeX gnuplot Micr○ $○ft
  19. 19. • (OS) • 1 • 24 • root • • Docker ※
  20. 20. 
 • echo > /etc/passwd • :(){:|:&};: • rm tmp /* */ • echo 'exec sl' > ~/.bashrc • echo {0000000000..9999999999} • alias emacs='vim' alias emacs='rm -rf /' sudo ln -s $ (which emacs) $(dirname $(which emacs))/vim • alias eval='eval eval'; eval • sudo apt-get remove glibc
  21. 21. • H4sICBmZ4lcAA2VsZgCrd/ VxY2RkZIABJgZmBhAvMcBEyIQBAUwYFBhgquCqgWpAVDMUs4I4AgwMjxvbHjdNftw 4mQuodgcLUHA3SMvOEKD6XbxA1tmGHSCB3QxgNgCMjcoWgwAAAA== • 32bit ELF • 140 (Twitter ) • eval eval ''n='''{1..'$(dc -e 1000vp)'}''' eval eval eval echo '''''''$(('''''''$n'' '''''*''''''''{2..$ ((1000/n))}''''''''))''' '''';'' | tr ' ' n | sort -n | uniq -u • 1000 • l='L${r}FR${l}F${l}RF${r}L' r='R${l}FL${r}F${r}LF${l}R' eval eval eval eval eval eval l= r= eval echo '$l' | { read a; b=${a%%F*}; echo "from turtle import *;speed(0);pensize(2);ms=min(screensize())*0.8;l=2*ms/(2**$ {#b}-1);up();setpos(-ms,-ms);down();${a}done()"; } | sed 's/L/ lt(90);/g;s/R/rt(90);/g;s/F/fd(l);/g' | python • ( ) •
  22. 22. • man • awk man awk • – (https:// blog.ueda.tech/?page_id=684) • 29 Perl ( 1 ) (https:// umidori.github.io/shellgei-29th-am/) • 30 Perl ( 2 ) (https:// umidori.github.io/shellgei-30th-am/) • (https://orebibou.com/) • - (http://d.hatena.ne.jp/m-hiyama/ 20071221/1198221671) •
  23. 23. • Software Design 2017 1 30 et al • AWK •
  24. 24. • • 30 • • 30 20 • 27 sed • https://blog.ueda.tech/?p=9283 • 1 • • • 20
  25. 25. • super_unko - Togetter (https://togetter.com/li/1145304) • ( ) • Raspberry Pi • on Python •
  26. 26. • GNU Emacs acronym expansions (https://www.gnu.org/fun/jokes/ gnuemacs.acro.exp.html) • Ver. 1.1 – (https:// blog.ueda.tech/?page_id=1434) • Vim vimshell - Togetter (https://togetter.com/li/1080646) • SHELQ: – (https:// blog.ueda.tech/?p=8862) • https://steers.jp/c/forkbomb_navy • T
  27. 27. May you have a happy ShellGei life!! Now, we can :(){:|:&};: in production!!

×