migrando de shell para ruby script
TRANSCRIPT
![Page 1: Migrando de Shell para Ruby script](https://reader033.vdocuments.site/reader033/viewer/2022042716/55aa6fbb1a28abbc208b456d/html5/thumbnails/1.jpg)
echo “echo “migrando de Shellmigrando de Shell””puts “puts “para Ruby scriptpara Ruby script””
@luizsanxes@luizsanxeshttp://s522.photobucket.com/user/HeartsofLoveRav/media/Clip-Art--shell-beach-clip-art-pearl-wallpaper-800x4801.jpg.htmlhttp://s522.photobucket.com/user/HeartsofLoveRav/media/Clip-Art--shell-beach-clip-art-pearl-wallpaper-800x4801.jpg.html
![Page 2: Migrando de Shell para Ruby script](https://reader033.vdocuments.site/reader033/viewer/2022042716/55aa6fbb1a28abbc208b456d/html5/thumbnails/2.jpg)
$ whoamiJava
PHP
RubyShellPostgreSQL
MySQL
MongoDB
Linux
Agile
Open SourceGit
Cloud Computing
Rails
![Page 3: Migrando de Shell para Ruby script](https://reader033.vdocuments.site/reader033/viewer/2022042716/55aa6fbb1a28abbc208b456d/html5/thumbnails/3.jpg)
$ whereis
![Page 4: Migrando de Shell para Ruby script](https://reader033.vdocuments.site/reader033/viewer/2022042716/55aa6fbb1a28abbc208b456d/html5/thumbnails/4.jpg)
http://www.osirixexperts.com/wp-content/uploads/2015/02/open-source-software-1.jpghttp://www.osirixexperts.com/wp-content/uploads/2015/02/open-source-software-1.jpg
![Page 5: Migrando de Shell para Ruby script](https://reader033.vdocuments.site/reader033/viewer/2022042716/55aa6fbb1a28abbc208b456d/html5/thumbnails/5.jpg)
Script
http://www.wellesley.edu/sites/default/files/script.jpghttp://www.wellesley.edu/sites/default/files/script.jpg
![Page 6: Migrando de Shell para Ruby script](https://reader033.vdocuments.site/reader033/viewer/2022042716/55aa6fbb1a28abbc208b456d/html5/thumbnails/6.jpg)
Linguagens de Script
![Page 7: Migrando de Shell para Ruby script](https://reader033.vdocuments.site/reader033/viewer/2022042716/55aa6fbb1a28abbc208b456d/html5/thumbnails/7.jpg)
É a linha de comando do Linux (e UNIX). É o shell quem interpreta a linha de comandos digitada pelo usuário no terminal e chama os programas desejados. Lê-se "xéu", como em "meu deu du xéu" :)
aurelio.net/shell
O que é shell?
![Page 8: Migrando de Shell para Ruby script](https://reader033.vdocuments.site/reader033/viewer/2022042716/55aa6fbb1a28abbc208b456d/html5/thumbnails/8.jpg)
Ruby é...
Uma linguagem dinâmica, open source com foco na simplicidade e na produtividade. Tem uma sintaxe elegante de leitura natural e fácil escrita.
www.ruby-lang.org
![Page 9: Migrando de Shell para Ruby script](https://reader033.vdocuments.site/reader033/viewer/2022042716/55aa6fbb1a28abbc208b456d/html5/thumbnails/9.jpg)
Então, simbora!
![Page 10: Migrando de Shell para Ruby script](https://reader033.vdocuments.site/reader033/viewer/2022042716/55aa6fbb1a28abbc208b456d/html5/thumbnails/10.jpg)
oi.sh
#!/bin/bash
echo "Oi, $1"
oi.rb
#!/usr/bin/env ruby
puts "Oi, #{ARGV[0]}"
![Page 11: Migrando de Shell para Ruby script](https://reader033.vdocuments.site/reader033/viewer/2022042716/55aa6fbb1a28abbc208b456d/html5/thumbnails/11.jpg)
$ chmod +x oi.*
![Page 12: Migrando de Shell para Ruby script](https://reader033.vdocuments.site/reader033/viewer/2022042716/55aa6fbb1a28abbc208b456d/html5/thumbnails/12.jpg)
$ ./oi.sh "Ambrósio"
Oi, Ambrósio
$ ./oi.rb "Ambrósio"
Oi, Ambrósio
![Page 13: Migrando de Shell para Ruby script](https://reader033.vdocuments.site/reader033/viewer/2022042716/55aa6fbb1a28abbc208b456d/html5/thumbnails/13.jpg)
Agora créu na velocidade três!
![Page 14: Migrando de Shell para Ruby script](https://reader033.vdocuments.site/reader033/viewer/2022042716/55aa6fbb1a28abbc208b456d/html5/thumbnails/14.jpg)
/etc/passwd
root:x:0:0:rootdaemon:x:1:1:daemonbin:x:2:2:binsys:x:3:3:syssync:x:4:65534:sync
#!/bin/bash
cat /etc/passwd | cut -d: -f1,5
#!/usr/bin/env ruby
IO.readlines("/etc/passwd").each do |line| array = line.split(":") puts array[0] + ":" + array[4]end
resultado
root:rootdaemon:daemonbin:binsys:syssync:sync
![Page 15: Migrando de Shell para Ruby script](https://reader033.vdocuments.site/reader033/viewer/2022042716/55aa6fbb1a28abbc208b456d/html5/thumbnails/15.jpg)
Ru - Ruby in your shell!
http://horaderelaxar.com.br/wp-content/uploads/2008/10/2-uma-mao-na-roda.jpghttp://horaderelaxar.com.br/wp-content/uploads/2008/10/2-uma-mao-na-roda.jpg
![Page 16: Migrando de Shell para Ruby script](https://reader033.vdocuments.site/reader033/viewer/2022042716/55aa6fbb1a28abbc208b456d/html5/thumbnails/16.jpg)
gem install ru
![Page 17: Migrando de Shell para Ruby script](https://reader033.vdocuments.site/reader033/viewer/2022042716/55aa6fbb1a28abbc208b456d/html5/thumbnails/17.jpg)
Centralizando texto
nomes.txtVovó MafaldaPapai PapudoSalci Fufu
awk 'printf "%" int(40+length($0)/2) "s\n", $0' nomes.txt
ru 'map(:center, 80)' nomes.txt
![Page 18: Migrando de Shell para Ruby script](https://reader033.vdocuments.site/reader033/viewer/2022042716/55aa6fbb1a28abbc208b456d/html5/thumbnails/18.jpg)
Imprimir a 2ª linha
nomes.txtVovó MafaldaPapai PapudoSalci Fufu
sed '2q;d' nomes.txt
ru '[1]' nomes.txt
![Page 19: Migrando de Shell para Ruby script](https://reader033.vdocuments.site/reader033/viewer/2022042716/55aa6fbb1a28abbc208b456d/html5/thumbnails/19.jpg)
Filtrar linhas
nomes.txtVovó MafaldaPapai PapudoSalci Fufu
cat nomes.txt | grep i
ru 'grep(/i/)' nomes.txt
![Page 20: Migrando de Shell para Ruby script](https://reader033.vdocuments.site/reader033/viewer/2022042716/55aa6fbb1a28abbc208b456d/html5/thumbnails/20.jpg)
github.com/tombenner/ru
E mais exemplos em
![Page 21: Migrando de Shell para Ruby script](https://reader033.vdocuments.site/reader033/viewer/2022042716/55aa6fbb1a28abbc208b456d/html5/thumbnails/21.jpg)
$ man books
![Page 22: Migrando de Shell para Ruby script](https://reader033.vdocuments.site/reader033/viewer/2022042716/55aa6fbb1a28abbc208b456d/html5/thumbnails/22.jpg)
$ sudo shutdown
about.me/luizsanches