annotate src/learn_bash.html.luan @ 46:89fdc29b296f

learn_bash work
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 05 Jan 2024 20:58:57 -0700
parents 14518d772090
children 84dd3edd03e9
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 <p></p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
375 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
376 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
377 dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
378 ~/learn $ cp file1 copied
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
379 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
380 copied dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
381 ~/learn $ mv copied moved
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
382 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
383 dir1/ file1 file2 file3 moved
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
384 ~/learn $ rm moved
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
385 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
386 dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
387 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
388
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
389 <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
390
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
391 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
392 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
393 dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
394 ~/learn $ mkdir dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
395 ~/learn $ touch dir2/d2file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
396 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
397 dir1/ dir2/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
398 ~/learn $ ls dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
399 d2file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
400 ~/learn $ rm dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
401 rm: dir2: is a directory
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
402 ~/learn $ rm -d dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
403 rm: dir2: Directory not empty
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
404 ~/learn $ rm dir2/d2file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
405 ~/learn $ rm -d dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
406 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
407 dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
408 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
409
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
410 <p></p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
411
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
412 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
413 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
414 dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
415 ~/learn $ mkdir dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
416 ~/learn $ touch dir2/d2file
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/ dir2/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
419 ~/learn $ rm -R dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
420 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
421 dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
422 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
423
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
424 <p></p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
425
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
426 <code block>
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/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
429 ~/learn $ cp dir1 dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
430 cp: dir1 is a directory (not copied).
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
431 ~/learn $ cp -R dir1 dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
432 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
433 dir1/ dir2/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
434 ~/learn $ ls dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
435 d1file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
436 ~/learn $ cp f* dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
437 ~/learn $ ls dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
438 d1file file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
439 ~/learn $ rm -R dir2
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 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
443
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
444 <p></p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
445
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
446 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
447 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
448 dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
449 ~/learn $ mkdir dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
450 ~/learn $ cp -R dir1 dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
451 ~/learn $ ls -F dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
452 dir1/
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
453 ~/learn $ ls -F dir2/dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
454 d1file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
455 ~/learn $ rm -R dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
456 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
457 dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
458 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
459
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
460 <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
461 <%
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
462 end
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
463 }
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
464 quote = {
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
465 title = [[Quoting]]
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
466 content = function()
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
467 %>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
468 <p></p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
469
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
470 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
471 ~/learn $ echo a b
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
472 a b
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
473 ~/learn $ echo "a b"
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
474 a b
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
475 ~/learn $ echo 'a b'
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
476 a b
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
477 ~/learn $ echo "a b" c
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
478 a b c
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
479 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
480
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
481 <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
482
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
483 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
484 ~/learn $ echo a\ \ \ b
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
485 a b
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
486 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
487
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
488 <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
489
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
490 <%
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
491 end
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 vars = {
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
494 title = [[Variables]]
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
495 content = function()
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
496 %>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
497 <p></p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
498
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
499 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
500 ~/learn $ echo $X
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
501
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
502 ~/learn $ X="some text"
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
503 ~/learn $ echo $X
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
504 some text
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
505 ~/learn $ echo "X is: $X"
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
506 X is: some text
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
507 ~/learn $ echo 'X is: $X'
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
508 X is: $X
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
509 ~/learn $ X="$X and more"
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
510 ~/learn $ echo $X
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
511 some text and more
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
512 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
513
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
514 <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>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
515 <%
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
516 end
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
517 }
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
518 bash_profile = {
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
519 title = [[.bash_profile]]
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
520 content = function()
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
521 %>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
522 <p>later</p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
523 <%
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
524 end
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
525 }
45
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
526 later = {
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
527 title = [[placeholder]]
41
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
528 content = function()
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
529 %>
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
530 <p>later</p>
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
531 <%
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
532 end
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
533 }
40
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
534 }
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
535
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
536
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
537 local function show_toc(content)
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
538 %>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
539 <ul>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
540 <%
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
541 for id, info in pairs(content) do
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
542 %>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
543 <li><a id="c_<%=id%>" href="#<%=id%>"><%=info.title%></a></li>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
544 <%
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
545 end
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
546 %>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
547 </ul>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
548 <%
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
549 end
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
550
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
551 local function show_content(content,h)
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
552 for id, info in pairs(content) do
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
553 %>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
554 <div heading>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
555 <h<%=h%>><a id="<%=id%>" href="#<%=id%>"><%=info.title%></a></h<%=h%>>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
556 <a href="#c_<%=id%>">contents</a>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
557 </div>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
558 <%
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
559 info.content()
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
560 end
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
561 end
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
562
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
563 return function()
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
564 Io.stdout = Http.response.text_writer()
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
565 %>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
566 <!doctype html>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
567 <html>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
568 <head>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
569 <% head() %>
45
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
570 <title>Reactionary Bash Tutorial</title>
40
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
571 </head>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
572 <body>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
573 <% header() %>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
574 <div content>
45
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
575 <h1><a href="learn.html">Reactionary Bash Tutorial</a></h1>
40
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
576 <hr>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
577 <h2>Contents</h2>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
578 <div toc>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
579 <% show_toc(content) %>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
580 </div>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
581 <hr>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
582 <% show_content(content,2) %>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
583 </div>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
584 </body>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
585 </html>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
586 <%
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
587 end