Day 1 of GA WDI program: we spent majority of the class in terminal(shell), getting comfortable with command line prompts. We also played with some Ruby in and Sublime Text. All in all, a good review of all the prep work on command line stuff. Ubuntu isn't as scary as when I first installed it yesterday.
tl;dr: Terminal Commands, Shebang #!/usr/bin/env ruby
, chmod a+x demo.rb
, Literals, cat, less.
file_name.md --> md stands for markdown file type
Ctrl +
to zoom in (in apple: Cmd +
)
Equivalent of Homebrew: sudo apt-get install
ls list the content of the directory that I am currently in ls -l list your files in list(detail) form
pushd similar to cd, but leaves a breadcrumb trail of where you have been --> while typing pushd, type the first letter (case sensitive) of the file name and press tab to autofill the remainder of the file name pushd .. go down one directory popd go back; popping back to one folder/directory up cd .. going back up one folder/directory pwd print working directory clear clearing the terminal space
<h6>Some commands:</h6>
```bash
irb interactive ruby
REPL Read Evaluate Print Loop (what irb does)
history while in bash (j@ubuntu:) shows history of what you have typed thus far
history10 while in bash--> shows the last 10 commands you have typed in terminal
man + xx shows manual for xx (you can type /keyword to search within manual for
keyword)
```bash
ruby --version longhand form
ruby -v shorthand form
ruby demo.rb runs demo.rb when you are in the same directory as the file cat demo.rb | ruby lets cat read out the file and | lets ruby handle the file ruby ./demo.rb runs demo.rb when you are NOT in the same directory as the file all these three yield the same result
<h5>Creating folders in terminal:</h5>
```bash
rm Code/ rm (recursive move) deletes everything in the Code file
rm -rf Code/ force delete (recursive force) everything in the Code directory
(whether it is directory or file)
pronounced "rum-rff"
mkdir -p Code/ makes a parent directory (-p stands for parent) Code;
mkdir -p Code/GA-Day1 makes both a parent directory Code (if it does not exist
already) and child directory GA-Day1; with a -p, it
would not complain if the parent directory does not
already exist
touch ./demo.rb "creates" (writes) demo.rb
in Mac: when you access the folder in GUI (home folder clicking the icon),
a .DS_Store folder is automatically generated.
cat file_name.rb concatenates (or prints) everything that is in the file name
less file_name.rb takes you to a program that shows you the content of the file
BSD vs. GNU --- Mac is based on BSD and Linux is based on GNU
Ctrl + N
to open a new tab in Sublime Text
with this line in place, you can now run the ruby file in terminal using: ./demo.rb or, ./file_name.rb
j@ubuntu:~/Code/GA-Day1$ ls -l total 3 -rw-rw-r-- 1 j j 11 Jun 17 14:42 demo.rb -rw-rw-r-- 1 j j 1502 Jun 17 12:33 Wk1_Mon(Day1).md
if you run ./demo.rb in command line now, you will get permission denied
j@ubuntu:~/Code/GA-Day1$ chmod a+x demo.rb
j@ubuntu:~/Code/GA-Day1$ ls -l total 3 -rwxrwxr-x 1 j j 11 Jun 17 14:42 demo.rb -rw-rw-r-- 1 j j 1502 Jun 17 12:33 Wk1_Mon(Day1).md
#=> now demo.rb may be run without ruby in front
- rw- r-- r-- (these are called sticky bit)
- owner/user - group - other r: read w: write x: execution a+x: all(user, group, other) + executable
Ruby Command Line Input/Output:
```Ruby
#!usr/bin/env ruby
flag = ARGV[0]
str = ARGV[1]
if '-C' == flag # good practice to keep constant literals on the
left hand side of a condition
# this makes sure that things fail
if it is not assigned correctly
puts('make all caps')
end
*Anything that gets typed into the command line is automatically
defaulted to a "String".
Unless you enter nothing, which will return a 'Nil'
(def): anything where what you see is what you get (not contained in a variable)
ex. 42 --> a literal number
ex. "hello world" --> a literal string
ex. regular expressions /re/
[], nil, {}, #
Briefly touched on MVC
**Follow-up Question: how does terminal/rails know which version of Ruby to run? (mentioned that different programs can run different versions of Ruby)
Short Ans: RVM file points to a certain PATH file which tells you which version of Ruby to run. More discussion on this on a later date.