annotate src/learn_bash.html.luan @ 47:84dd3edd03e9

learn_bash work
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 06 Jan 2024 21:28:44 -0700
parents 89fdc29b296f
children 889e3c2d2699
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
40
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local pairs = Luan.pairs or error()
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local Io = require "luan:Io.luan"
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local Http = require "luan:http/Http.luan"
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local Shared = require "site:/lib/Shared.luan"
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local head = Shared.head or error()
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local header = Shared.header or error()
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local content = {
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 intro = {
45
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
13 title = [[Introduction]]
40
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 content = function()
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 %>
46
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
16 <p>I really don't want to write this tutorial, but all the existing <a href="bash.html">Bash</a> tutorials are so horrible that I have no choice. I looked at books, websites, and YouTube - all horrible. They don't start with the basics. They include all kinds of useless crap. And they don't explain core concepts. So I have no choice but to write this damn thing for my <a href="http://localhost:8080/learn.html#bash">Learn Reactionary Programming</a> Bash lesson.</p>
40
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17
45
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
18 <p>I will focus on Mac and Windows. I don't have Linux, and I hate Linux, so I won't discuss it. Most of Bash is the same on Mac and Windows, but where they differ, I will discuss both.</p>
40
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 <%
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 end
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 }
45
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
22 access = {
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
23 title = [[Running Bash]]
40
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 content = function()
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 %>
45
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
26 <p>How you access Bash depends on your operating system. If you are on a Mac then you access Bash through the Mac Terminal which is found in "Applications > Utilities > Terminal.app". Be sure to <a href="https://www.howtogeek.com/444596/how-to-change-the-default-shell-to-bash-in-macos-catalina/">set the default shell to Bash</a>. If you are on Windows then install <a href="https://www.msys2.org/">MSYS2</a>. The default terminal isn't so good, so I suggest <a href="https://www.msys2.org/docs/terminals/#windows-terminal">using the Windows Terminal</a>.</p>
40
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 <%
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 end
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 }
45
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
30 start = {
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
31 title = [[Getting Started]]
41
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
32 content = function()
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
33 %>
45
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
34 <p>When I start Bash on my Mac I see:</p>
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
35
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
36 <code block>
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
37 Last login: Thu Jan 4 23:25:35 on ttys004
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
38
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
39 The default interactive shell is now zsh.
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
40 To update your account to use zsh, please run `chsh -s /bin/zsh`.
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
41 For more details, please visit https://support.apple.com/kb/HT208050.
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
42 ~ $
44
5b4d5cf453a8 start bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 43
diff changeset
43
45
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
44 </code>
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
45
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
46 <p>On Windows - MSYS2 I just see:</p>
44
5b4d5cf453a8 start bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 43
diff changeset
47
45
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
48 <code block>
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
49 ~ $
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
50
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
51 </code>
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
52
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
53 <p>The line with the <b><code>$</code></b> is the command prompt. The cursor is at the end of it, and if I type, my text will go there. You may have different text before the <b><code>$</code></b> which is okay, but the line should end with <b><code>$</code></b>. If it doesn't, something is wrong.</p>
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
54
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
55 <p>Now type "qqq". When I say type "whatever", you should type return/enter at the end. Only when you type return/enter will Bash process what you typed. Now you should see:</p>
44
5b4d5cf453a8 start bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 43
diff changeset
56
45
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
57 <code block>
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
58 ~ $ qqq
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
59 -bash: qqq: command not found
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
60 ~ $
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
61 </code>
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
62
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
63 <p>Bash doesn't know what "qqq" means and says so. Now try the following... Note that you type what is after the <b><code>$</code></b> and Bash should respond as shown.</p>
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
64
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
65 <code block>
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
66 ~ $ echo hi
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
67 hi
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
68 ~ $ echo how are you
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
69 how are you
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
70 ~ $ echo bye
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
71 bye
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
72 </code>
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
73
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
74 <p>The <code>echo</code> command just echos what comes after. Now press the up-arrow on your keyboard. This should put the previous command where your cursor is. Up-arrow again brings the command before that. Try down-arrow and left-arrow and right-arrow. You can use this to navigate through your command history. The delete key also works for editing lines. And of course you can type. When you press return/enter then Bash will get your edited command and process it.</p>
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
75
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
76 <p>When you enter <code>echo how are you</code>, <code>echo</code> is the command. This command has 3 arguments: <code>how</code>, <code>are</code>, and <code>you</code>. Commands and arguments are separated with spaces. It doesn't matter how many spaces, so:</p>
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
77
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
78 <code block>
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
79 ~ $ echo how are you
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
80 how are you
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
81 </code>
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
82
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
83 <p><code>echo</code> just returns the arguments separated by one space.</p>
41
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
84 <%
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
85 end
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
86 }
45
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
87 man = {
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
88 title = [[The "man" Command]]
41
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
89 content = function()
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
90 %>
45
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
91 <p>Enter:</p>
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
92 <code block>
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
93 ~ $ man echo
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
94 </code>
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
95
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
96 <p>You should get:</p>
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
97
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
98 <code block>
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
99
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
100 ECHO(1) BSD General Commands Manual ECHO(1)
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
101
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
102 NAME
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
103 echo -- write arguments to the standard output
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
104
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
105 SYNOPSIS
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
106 echo [-n] [string ...]
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
107
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
108 DESCRIPTION
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
109 The echo utility writes any specified operands, separated by single blank
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
110 (` ') characters and followed by a newline (`\n') character, to the stan-
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
111 dard output.
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
112
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
113 The following option is available:
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
114
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
115 -n Do not print the trailing newline character. This may also be
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
116 achieved by appending `\c' to the end of the string, as is done by
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
117 iBCS2 compatible systems. Note that this option as well as the
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
118 effect of `\c' are implementation-defined in IEEE Std 1003.1-2001
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
119 (``POSIX.1'') as amended by Cor. 1-2002. Applications aiming for
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
120 maximum portability are strongly encouraged to use printf(1) to
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
121 suppress the newline character.
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
122 :
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
123 </code>
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
124
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
125 <p>But if you are on Windows, you may not have <code>man</code> installed. In that case, do:</p>
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
126
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
127 <code block>
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
128 ~ $ pacman -S man-db
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
129 </code>
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
130
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
131 <p>to install <code>man</code> as described <a href="https://packages.msys2.org/package/man-db">here</a> and then try <code>man echo</code> again.</p>
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
132
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
133 <p>The <code>man</code> command shows documentation of commands. Unfortunately it has a silly user interface based on memorizing keys, so I will just tell you the few keys you need. Down-arrow and up-arrow move down and up by one line. The space key moves down by one page. And most importantly, typing "q" quits and takes you back to Bash. You just have to memorize this.</p>
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
134
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
135 <p>Now try entering <code>man man</code>. You don't need all the stuff shown, but you can see what a complicated man page looks like. You can use <code>man</code> to get the documentation of other commands as I discuss them.</p>
41
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
136 <%
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
137 end
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
138 }
46
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
139 dirs = {
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
140 title = [[Directories]]
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
141 content = function()
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
142 %>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
143 <p>You should be familiar with Mac Finder or Windows File Explorer, and you should know from this that directories (also called "folders") are organized into a tree.</p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
144
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
145 <p>On Mac:</p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
146
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
147 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
148 ~ $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
149 /Users/fschmidt
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
150 ~ $ open .
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
151 ~ $
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
152 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
153
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
154 <p>On Windows:</p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
155
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
156 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
157 ~ $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
158 /home/fschmidt
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
159 ~ $ explorer .
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
160 ~ $
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
161 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
162
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
163 <p>When using Bash, you are always in some directory, called the current directory or the working directory. <code>pwd</code> shows you the full path to this directory. Do <code>man pwd</code> for details.<p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
164
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
165 <p>Continuing on my Mac:</p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
166
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
167 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
168 ~ $ mkdir learn
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
169 ~ $ cd learn
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
170 ~/learn $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
171 /Users/fschmidt/learn
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
172 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
173
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
174 <p><code>mkdir</code> makes a directory in the current directory. You should be able to see the created directory in Mac Finder or Windows File Explorer. <code>cd</code> stands for "change directory". This changes the current directory. <code>cd</code> is a built-in command (built into Bash), and <code>man</code> isn't useful with built-in commands, so instead of <code>man cd</code>, try <code>help cd</code>. Continuing...</p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
175
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
176 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
177 ~/learn $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
178 /Users/fschmidt/learn
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
179 ~/learn $ ls
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
180 ~/learn $ touch file1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
181 ~/learn $ ls
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
182 file1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
183 ~/learn $ touch file2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
184 ~/learn $ touch file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
185 ~/learn $ ls
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
186 file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
187 ~/learn $ mkdir dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
188 ~/learn $ ls
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
189 dir1 file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
190 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
191 dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
192 ~/learn $ ls -a
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
193 . .. dir1 file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
194 ~/learn $ ls -a -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
195 ./ ../ dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
196 ~/learn $ ls -aF
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
197 ./ ../ dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
198 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
199
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
200 <p><code>ls</code> lists files and <code>touch</code> creates an empty file. Arguments that start with "-" are options. Do <code>man ls</code> to see what the options I used do. <code>-F</code> appends a "/" to directories, and <code>-a</code> shows files starting with "." which are usually hidden. Options can be combined.</p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
201
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
202 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
203 ~/learn $ ls file1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
204 file1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
205 ~/learn $ ls qqq
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
206 ls: qqq: No such file or directory
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
207 ~/learn $ ls file1 qqq file2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
208 ls: qqq: No such file or directory
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
209 file1 file2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
210 ~/learn $ ls dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
211 ~/learn $ touch dir1/d1file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
212 ~/learn $ ls dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
213 d1file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
214 ~/learn $ ls -d dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
215 dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
216 ~/learn $ ls file1 file2 dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
217 file1 file2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
218
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
219 dir1:
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
220 d1file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
221 ~/learn $ ls -d file1 file2 dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
222 dir1 file1 file2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
223 ~/learn $ ls -dF file1 file2 dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
224 dir1/ file1 file2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
225 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
226
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
227 <p>Without file arguments, <code>ls</code> lists files in the current directory. With file arguments, it lists those files if they exist. If the file is a directory, it will list what is in the directory unless the <code>-d</code> option is used.</p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
228
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
229 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
230 ~/learn $ ls
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
231 dir1 file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
232 ~/learn $ ls .
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
233 dir1 file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
234 ~/learn $ ls -d .
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
235 .
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
236 ~/learn $ ls -dF .
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
237 ./
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
238 ~/learn $ ls ./file1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
239 ./file1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
240 ~/learn $ ls dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
241 d1file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
242 ~/learn $ ls ./dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
243 d1file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
244 ~/learn $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
245 /Users/fschmidt/learn
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
246 ~/learn $ cd .
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
247 ~/learn $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
248 /Users/fschmidt/learn
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
249 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
250
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
251 <p><code>.</code> is the current directory.</p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
252
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
253 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
254 ~/learn $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
255 /Users/fschmidt/learn
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
256 ~/learn $ cd dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
257 ~/learn/dir1 $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
258 /Users/fschmidt/learn/dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
259 ~/learn/dir1 $ ls .
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
260 d1file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
261 ~/learn/dir1 $ ls ..
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
262 dir1 file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
263 ~/learn/dir1 $ cd ..
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
264 ~/learn $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
265 /Users/fschmidt/learn
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
266 ~/learn $ cd dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
267 ~/learn/dir1 $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
268 /Users/fschmidt/learn/dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
269 ~/learn/dir1 $ cd ../..
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
270 ~ $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
271 /Users/fschmidt
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
272 ~ $ cd learn
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
273 ~/learn $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
274 /Users/fschmidt/learn
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
275 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
276
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
277 <p><code>..</code> is the parent directory.</p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
278
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
279 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
280 ~/learn $ echo *
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
281 dir1 file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
282 ~/learn $ echo d*
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
283 dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
284 ~/learn $ echo f*
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
285 file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
286 ~/learn $ echo *1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
287 dir1 file1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
288 ~/learn $ echo dir1/*
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
289 dir1/d1file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
290 ~/learn $ echo */*
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
291 dir1/d1file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
292 ~/learn $ echo qqq*
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
293 qqq*
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
294 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
295
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
296 <p><code>*</code> does wildcard matching of files. It is important to understand that Bash does the wildcard matching and then passes the resulting arguments to the command. <code>echo</code> never sees the "*" unless there is no match.</p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
297
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
298 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
299 ~/learn $ ls *
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
300 file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
301
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
302 dir1:
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
303 d1file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
304 ~/learn $ ls -dF *
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
305 dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
306 ~/learn $ ls -dF d*
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
307 dir1/
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
308 ~/learn $ ls -dF f*
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
309 file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
310 ~/learn $ ls -dF *1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
311 dir1/ file1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
312 ~/learn $ ls dir1/*
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
313 dir1/d1file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
314 ~/learn $ ls */*
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
315 dir1/d1file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
316 ~/learn $ ls -dF qqq*
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
317 ls: qqq*: No such file or directory
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
318 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
319
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
320 <p>Should be self-explanatory.</p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
321
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
322 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
323 ~/learn $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
324 /Users/fschmidt/learn
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
325 ~/learn $ cd ~
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
326 ~ $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
327 /Users/fschmidt
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
328 ~ $ cd learn/dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
329 ~/learn/dir1 $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
330 /Users/fschmidt/learn/dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
331 ~/learn/dir1 $ cd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
332 ~ $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
333 /Users/fschmidt
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
334 ~ $ cd ~/learn
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
335 ~/learn $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
336 /Users/fschmidt/learn
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
337 ~/learn $ echo ~
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
338 /Users/fschmidt
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
339 ~/learn $ echo .
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
340 .
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
341 ~/learn $ echo ..
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
342 ..
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
343 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
344
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
345 <p><code>~</code> means your home directory. <code>cd</code> without arguments is the same as <code>cd ~</code>. <code>~</code> is expanded into your home directory by Bash.</p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
346
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
347 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
348 ~/learn $ ls -ltF
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
349 total 0
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
350 drwxr-xr-x 3 fschmidt staff 96 Jan 5 02:33 dir1/
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
351 -rw-r--r-- 1 fschmidt staff 0 Jan 5 02:21 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
352 -rw-r--r-- 1 fschmidt staff 0 Jan 5 02:21 file2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
353 -rw-r--r-- 1 fschmidt staff 0 Jan 5 02:21 file1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
354 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
355
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
356 <p><code>-l</code> gives you this ugly techy format. You get the date that the file was last modified. Before the date is the file size. <code>-t</code> sorts by date descending.</p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
357
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
358 <p>Lastly I will describe autocompletion. I type <code>echo d</code> without enter/return but instead then press the tab key. It autocompletes to <code>echo dir1/</code>. I press tab again and it autocompletes to <code>echo dir1/d1file</code>. Pressing tab while entering a file or directory makes Bash try to autocomplete using matching file names. If I enter <code>echo f</code> and press tab, I get <code>echo file</code>. It doesn't know which to choose next. Another tab just beeps. And another tab shows me the options like this:</p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
359
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
360 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
361 ~/learn $ echo file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
362 file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
363 ~/learn $ echo file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
364 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
365
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
366 <p>In general, you can press tab anytime while entering a file name and see what happens. Autocompletion saves a lot of typing.</p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
367 <%
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
368 end
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
369 }
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
370 files = {
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
371 title = [[Working with Files]]
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
372 content = function()
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
373 %>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
374 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
375 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
376 dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
377 ~/learn $ cp file1 copied
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
378 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
379 copied dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
380 ~/learn $ mv copied moved
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
381 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
382 dir1/ file1 file2 file3 moved
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
383 ~/learn $ rm moved
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
384 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
385 dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
386 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
387
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
388 <p><code>cp</code> copies files or directories. <code>mv</code> moves files or directories. <code>rm</code> removes files or directories. See the <code>man</code> pages of these commands for details.</p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
389
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
390 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
391 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
392 dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
393 ~/learn $ mkdir dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
394 ~/learn $ touch dir2/d2file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
395 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
396 dir1/ dir2/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
397 ~/learn $ ls dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
398 d2file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
399 ~/learn $ rm dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
400 rm: dir2: is a directory
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
401 ~/learn $ rm -d dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
402 rm: dir2: Directory not empty
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
403 ~/learn $ rm dir2/d2file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
404 ~/learn $ rm -d dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
405 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
406 dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
407 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
408
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
409 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
410 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
411 dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
412 ~/learn $ mkdir dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
413 ~/learn $ touch dir2/d2file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
414 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
415 dir1/ dir2/ file1 file2 file3
47
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
416 ~/learn $ rm -r dir2
46
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
417 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
418 dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
419 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
420
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
421 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
422 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
423 dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
424 ~/learn $ cp dir1 dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
425 cp: dir1 is a directory (not copied).
47
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
426 ~/learn $ cp -r dir1 dir2
46
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
427 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
428 dir1/ dir2/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
429 ~/learn $ ls dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
430 d1file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
431 ~/learn $ cp f* dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
432 ~/learn $ ls dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
433 d1file file1 file2 file3
47
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
434 ~/learn $ rm -r dir2
46
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
435 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
436 dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
437 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
438
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
439 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
440 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
441 dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
442 ~/learn $ mkdir dir2
47
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
443 ~/learn $ cp -r dir1 dir2
46
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
444 ~/learn $ ls -F dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
445 dir1/
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
446 ~/learn $ ls -F dir2/dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
447 d1file
47
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
448 ~/learn $ rm -r dir2
46
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
449 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
450 dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
451 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
452
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
453 <p>I could explain all this, but I won't. You should learn to understand commands and their options using <code>man</code> and by playing with them. Don't continue until you completely understand the above.</p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
454 <%
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
455 end
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
456 }
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
457 quote = {
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
458 title = [[Quoting]]
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
459 content = function()
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
460 %>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
461
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
462 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
463 ~/learn $ echo a b
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
464 a b
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
465 ~/learn $ echo "a b"
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
466 a b
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
467 ~/learn $ echo 'a b'
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
468 a b
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
469 ~/learn $ echo "a b" c
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
470 a b c
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
471 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
472
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
473 <p>Bash treats text in quotes as one argument. So in <code>echo a b</code>, <code>echo</code> has two arguments: "a" and "b". In <code>echo "a b"</code>, <code>echo</code> has one argument: "<span pre>a b</span>". In <code>echo 'a b'</code>, <code>echo</code> has one argument: "<span pre>a b</span>". In <code>echo "a b" c</code>, <code>echo</code> has two arguments: "<span pre>a b</span>" and "c".</p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
474
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
475 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
476 ~/learn $ echo a\ \ \ b
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
477 a b
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
478 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
479
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
480 <p>Outside of quotes, <code>\ </code> is not treated as a separator, but rather is treated as a space character that is part of the argument.</p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
481
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
482 <%
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
483 end
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
484 }
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
485 vars = {
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
486 title = [[Variables]]
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
487 content = function()
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
488 %>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
489
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
490 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
491 ~/learn $ echo $X
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
492
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
493 ~/learn $ X="some text"
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
494 ~/learn $ echo $X
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
495 some text
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
496 ~/learn $ echo "X is: $X"
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
497 X is: some text
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
498 ~/learn $ echo 'X is: $X'
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
499 X is: $X
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
500 ~/learn $ X="$X and more"
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
501 ~/learn $ echo $X
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
502 some text and more
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
503 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
504
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
505 <p>Here <code>X</code> is a variable. You get its value with <code>$X</code>. This also works inside double-quotes but not inside single-quotes.</p>
47
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
506
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
507 <p>There are special variables called environment variables that are used by Bash.</p>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
508
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
509 <code block>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
510 ~/learn $ echo $PATH
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
511 /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/fschmidt/Dropbox/bin:/Users/fschmidt/hg/luan/scripts:/usr/local/opt/postgresql@9.5/bin
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
512 ~/learn $ which ls
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
513 /bin/ls
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
514 ~/learn $ cd /bin
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
515 /bin $ pwd
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
516 /bin
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
517 /bin $ ls
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
518 [ dd launchctl pwd test
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
519 bash df link rm unlink
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
520 cat echo ln rmdir wait4path
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
521 chmod ed ls sh zsh
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
522 cp expr mkdir sleep
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
523 csh hostname mv stty
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
524 dash kill pax sync
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
525 date ksh ps tcsh
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
526 /bin $ ls -F
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
527 [* dd* launchctl* pwd* test*
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
528 bash* df* link* rm* unlink*
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
529 cat* echo* ln* rmdir* wait4path*
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
530 chmod* ed* ls* sh* zsh*
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
531 cp* expr* mkdir* sleep*
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
532 csh* hostname* mv* stty*
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
533 dash* kill* pax* sync*
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
534 date* ksh* ps* tcsh*
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
535 /bin $ cd ~/learn
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
536 ~/learn $
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
537 </code>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
538
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
539 <p><code>PATH</code> is an environment variable containing a list of directories separated by <code>:</code> that are searched for commands by Bash. The <code>which</code> command shows the full path to a command. <code>ls -F</code> appends a <code>*</code> to executable commands.</p>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
540
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
541 <code block>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
542 ~/learn $ subl file1
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
543 -bash: subl: command not found
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
544 ~/learn $ "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" file1
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
545 ~/learn $ PATH="$PATH:/Applications/Sublime Text.app/Contents/SharedSupport/bin"
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
546 ~/learn $ echo $PATH
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
547 /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/fschmidt/Dropbox/bin:/Users/fschmidt/hg/luan/scripts:/usr/local/opt/postgresql@9.5/bin:/Applications/Sublime Text.app/Contents/SharedSupport/bin
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
548 ~/learn $ subl file1
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
549 ~/learn $
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
550 </code>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
551
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
552 <p>Here I edit the file <code>file1</code> with <a href="http://localhost:8080/learn.html#editor">Sublime Text</a>, first by using the full path, and then by adding the directory to <code>PATH</code> so that Bash can find <code>subl</code>.</p>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
553
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
554 <p>I have Microsoft Word on Windows. From the Windows Command Prompt (not Bash):</p>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
555
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
556 <code block>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
557 C:\Users\fschmidt>winword
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
558
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
559 C:\Users\fschmidt>where winword
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
560 C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
561 </code>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
562
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
563 <p><code>winword</code> runs Microsoft Word. The Command Prompt <code>where</code> command is like the Bash <code>which</code> command. So now on MSYS2:</p>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
564
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
565 <code block>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
566 ~ $ winword
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
567 bash: winword: command not found
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
568 ~ $ echo $PATH
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
569 /usr/local/bin:/usr/bin:/bin:/opt/bin:/c/Windows/System32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/c/Program Files/TortoiseHg:/c/Program Files/Java/jdk1.8.0_202/bin
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
570 ~ $ PATH="$PATH:/c/Program Files/Microsoft Office/root/Office16"
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
571 ~ $ echo $PATH
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
572 /usr/local/bin:/usr/bin:/bin:/opt/bin:/c/Windows/System32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/c/Program Files/TortoiseHg:/c/Program Files/Java/jdk1.8.0_202/bin:/c/Program Files/Microsoft Office/root/Office16
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
573 ~ $ winword
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
574 ~ $
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
575 </code>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
576
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
577 <p>Returning to the Mac, there is another way to run applications found in Finder's "Applications" simply as applications instead of as commands.</p>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
578
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
579 <code block>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
580 ~/learn $ open -a 'Sublime Text' file1
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
581 </code>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
582
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
583 <p>Another useful environment variable is <code>PS1</code> which controls the command prompt. I already have this set up, but if I didn't:</p>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
584
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
585 <code block>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
586 Franklins-MacBook-Pro:learn fschmidt$ echo $PS1
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
587 \h:\W \u\$
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
588 Franklins-MacBook-Pro:learn fschmidt$ PS1="\w $ "
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
589 ~/learn $ echo $PS1
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
590 \w $
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
591 ~/learn $
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
592 </code>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
593
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
594 <p>Google "bash PS1" for more info.</p>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
595
46
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
596 <%
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
597 end
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
598 }
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
599 bash_profile = {
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
600 title = [[.bash_profile]]
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
601 content = function()
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
602 %>
47
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
603 <code block>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
604 ~/learn $ cd
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
605 ~ $ ls .bash_profile
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
606 .bash_profile
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
607 </code>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
608
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
609 <p>If <code>.bash_profile</code> isn't found then do <code>touch .bash_profile</code> to create it. This file contains Bash commands that are run when Bash starts. If you already have this file, it is likely to contain comments that start with <code>#</code>. Comments are ignored like this:</p>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
610
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
611 <code block>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
612 ~ $ # comment line, does nothing
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
613 ~ $ echo whatever # end of line comment
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
614 whatever
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
615 ~ $
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
616 </code>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
617
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
618 <p>To edit <code>.bash_profile</code> on a Mac, you can do:</p>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
619
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
620 <code block>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
621 ~ $ open -a 'Sublime Text' .bash_profile
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
622 </code>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
623
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
624 <p>To edit <code>.bash_profile</code> on Windows, you can do:</p>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
625
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
626 <code block>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
627 ~ $ notepad .bash_profile
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
628 </code>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
629
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
630 <p>Now try adding this line to <code>.bash_profile</code>:</p>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
631
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
632 <code block>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
633 echo hello there
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
634 </code>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
635
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
636 <p>Now when you open a new Bash terminal, you should see "hello there". <code>.bash_profile</code> runs when Bash is started by opening a new Bash terminal.</p>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
637
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
638 <p>I set <code>PS1</code> and <code>PATH</code> in <code>.bash_profile</code> to have the command prompt I want, and access to the commands that I want. I suggest that you make the <a href="https://www.sublimetext.com/docs/command_line.html">Sublime Text command</a> <code>subl</code> available in <code>PATH</code>.</p>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
639
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
640 <%
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
641 end
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
642 }
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
643 ctrl_c = {
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
644 title = [[Control+c]]
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
645 content = function()
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
646 %>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
647 <code block>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
648 ~/learn $ sleep 3
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
649 ~/learn $ sleep 30
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
650 ^C
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
651 ~/learn $
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
652 </code>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
653
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
654 <p><code>sleep 3</code> sleeps for 3 seconds, meaning it does nothing for 3 seconds. I waited 3 seconds for this command to finish. Then I ran <code>sleep 30</code> which would sleep for 30 seconds, but I lost my patience and pressed control+c which interrupts the program and breaks out of it. You can try control+c if you ever get stuck waiting for a command to finish.</p>
46
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
655 <%
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
656 end
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
657 }
45
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
658 later = {
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
659 title = [[placeholder]]
41
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
660 content = function()
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
661 %>
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
662 <p>later</p>
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
663 <%
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
664 end
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
665 }
40
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
666 }
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
667
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
668
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
669 local function show_toc(content)
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
670 %>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
671 <ul>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
672 <%
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
673 for id, info in pairs(content) do
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
674 %>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
675 <li><a id="c_<%=id%>" href="#<%=id%>"><%=info.title%></a></li>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
676 <%
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
677 end
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
678 %>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
679 </ul>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
680 <%
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
681 end
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
682
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
683 local function show_content(content,h)
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
684 for id, info in pairs(content) do
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
685 %>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
686 <div heading>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
687 <h<%=h%>><a id="<%=id%>" href="#<%=id%>"><%=info.title%></a></h<%=h%>>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
688 <a href="#c_<%=id%>">contents</a>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
689 </div>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
690 <%
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
691 info.content()
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
692 end
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
693 end
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
694
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
695 return function()
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
696 Io.stdout = Http.response.text_writer()
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
697 %>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
698 <!doctype html>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
699 <html>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
700 <head>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
701 <% head() %>
45
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
702 <title>Reactionary Bash Tutorial</title>
40
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
703 </head>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
704 <body>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
705 <% header() %>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
706 <div content>
45
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
707 <h1><a href="learn.html">Reactionary Bash Tutorial</a></h1>
40
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
708 <hr>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
709 <h2>Contents</h2>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
710 <div toc>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
711 <% show_toc(content) %>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
712 </div>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
713 <hr>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
714 <% show_content(content,2) %>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
715 </div>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
716 </body>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
717 </html>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
718 <%
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
719 end