annotate src/learn_bash.html.luan @ 57:536dc2d435ea

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 14 Jan 2024 23:30:38 -0700
parents 3082eaf8457d
children b1982e401900
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 %>
50
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
16 <p>I really don't want to write this tutorial, but all the existing Bash 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 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
49
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
18 <p><a href="bash.html">Bash</a> is a <a href="https://en.wikipedia.org/wiki/Unix_shell">shell</a>, one of many, but the one I prefer. 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
49
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
74 <p>The <code>echo</code> command just echoes 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>
45
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>
49
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
84
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
85 <code block>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
86 ~ $ echo one; echo two
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
87 one
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
88 two
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
89 </code>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
90
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
91 <p>You can put multiple commands on one line separated by a <code>;</code>.</p>
41
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
92 <%
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
93 end
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
94 }
45
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
95 man = {
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
96 title = [[The "man" Command]]
41
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
97 content = function()
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
98 %>
45
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
99 <p>Enter:</p>
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
100 <code block>
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
101 ~ $ man echo
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
102 </code>
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
103
49
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
104 <p>You should get something like:</p>
45
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
105
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
106 <code block>
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 ECHO(1) BSD General Commands Manual ECHO(1)
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
109
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
110 NAME
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
111 echo -- write arguments to the standard 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 SYNOPSIS
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
114 echo [-n] [string ...]
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
115
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
116 DESCRIPTION
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
117 The echo utility writes any specified operands, separated by single blank
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
118 (` ') characters and followed by a newline (`\n') character, to the stan-
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
119 dard output.
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
120
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
121 The following option is available:
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 -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
124 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
125 iBCS2 compatible systems. Note that this option as well as the
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
126 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
127 (``POSIX.1'') as amended by Cor. 1-2002. Applications aiming for
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
128 maximum portability are strongly encouraged to use printf(1) to
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
129 suppress the newline character.
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 </code>
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>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
134
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
135 <code block>
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
136 ~ $ pacman -S man-db
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
137 </code>
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
138
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
139 <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
140
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
141 <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
142
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
143 <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
144 <%
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
145 end
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
146 }
46
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
147 dirs = {
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
148 title = [[Directories]]
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
149 content = function()
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
150 %>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
151 <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
152
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
153 <p>On Mac:</p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
154
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
155 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
156 ~ $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
157 /Users/fschmidt
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
158 ~ $ open .
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
159 ~ $
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
160 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
161
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
162 <p>On Windows:</p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
163
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
164 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
165 ~ $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
166 /home/fschmidt
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
167 ~ $ explorer .
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
168 ~ $
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
169 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
170
49
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
171 <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. <code>open .</code> should open the Mac Finder for the current directory, and <code>explorer .</code> should open the Windows File Explorer for the current directory.<p>
46
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
172
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
173 <p>Continuing on my Mac:</p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
174
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
175 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
176 ~ $ mkdir learn
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
177 ~ $ cd learn
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
178 ~/learn $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
179 /Users/fschmidt/learn
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
180 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
181
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
182 <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
183
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
184 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
185 ~/learn $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
186 /Users/fschmidt/learn
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
187 ~/learn $ ls
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
188 ~/learn $ touch file1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
189 ~/learn $ ls
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
190 file1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
191 ~/learn $ touch file2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
192 ~/learn $ touch file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
193 ~/learn $ ls
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
194 file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
195 ~/learn $ mkdir dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
196 ~/learn $ ls
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 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
199 dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
200 ~/learn $ ls -a
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
201 . .. dir1 file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
202 ~/learn $ ls -a -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
203 ./ ../ dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
204 ~/learn $ ls -aF
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
205 ./ ../ dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
206 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
207
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
208 <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
209
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
210 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
211 ~/learn $ ls file1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
212 file1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
213 ~/learn $ ls qqq
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
214 ls: qqq: No such file or directory
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
215 ~/learn $ ls file1 qqq file2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
216 ls: qqq: No such file or directory
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 ~/learn $ ls dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
219 ~/learn $ touch dir1/d1file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
220 ~/learn $ ls dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
221 d1file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
222 ~/learn $ ls -d dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
223 dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
224 ~/learn $ ls file1 file2 dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
225 file1 file2
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 dir1:
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
228 d1file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
229 ~/learn $ ls -d file1 file2 dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
230 dir1 file1 file2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
231 ~/learn $ ls -dF file1 file2 dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
232 dir1/ file1 file2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
233 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
234
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
235 <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
236
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
237 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
238 ~/learn $ ls
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
239 dir1 file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
240 ~/learn $ ls .
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
241 dir1 file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
242 ~/learn $ ls -d .
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
243 .
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
244 ~/learn $ ls -dF .
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
245 ./
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
246 ~/learn $ ls ./file1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
247 ./file1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
248 ~/learn $ ls dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
249 d1file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
250 ~/learn $ ls ./dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
251 d1file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
252 ~/learn $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
253 /Users/fschmidt/learn
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
254 ~/learn $ cd .
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
255 ~/learn $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
256 /Users/fschmidt/learn
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
257 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
258
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
259 <p><code>.</code> is the current directory.</p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
260
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
261 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
262 ~/learn $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
263 /Users/fschmidt/learn
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
264 ~/learn $ cd dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
265 ~/learn/dir1 $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
266 /Users/fschmidt/learn/dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
267 ~/learn/dir1 $ ls .
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
268 d1file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
269 ~/learn/dir1 $ ls ..
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
270 dir1 file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
271 ~/learn/dir1 $ cd ..
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
272 ~/learn $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
273 /Users/fschmidt/learn
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
274 ~/learn $ cd dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
275 ~/learn/dir1 $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
276 /Users/fschmidt/learn/dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
277 ~/learn/dir1 $ cd ../..
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
278 ~ $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
279 /Users/fschmidt
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
280 ~ $ cd learn
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
281 ~/learn $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
282 /Users/fschmidt/learn
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
283 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
284
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
285 <p><code>..</code> is the parent directory.</p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
286
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
287 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
288 ~/learn $ echo *
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
289 dir1 file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
290 ~/learn $ echo d*
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
291 dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
292 ~/learn $ echo f*
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
293 file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
294 ~/learn $ echo *1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
295 dir1 file1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
296 ~/learn $ echo dir1/*
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
297 dir1/d1file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
298 ~/learn $ echo */*
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
299 dir1/d1file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
300 ~/learn $ echo qqq*
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
301 qqq*
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
302 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
303
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
304 <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
305
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
306 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
307 ~/learn $ ls *
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
308 file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
309
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
310 dir1:
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
311 d1file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
312 ~/learn $ ls -dF *
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
313 dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
314 ~/learn $ ls -dF d*
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
315 dir1/
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
316 ~/learn $ ls -dF f*
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
317 file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
318 ~/learn $ ls -dF *1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
319 dir1/ file1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
320 ~/learn $ ls dir1/*
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
321 dir1/d1file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
322 ~/learn $ ls */*
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
323 dir1/d1file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
324 ~/learn $ ls -dF qqq*
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
325 ls: qqq*: No such file or directory
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
326 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
327
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
328 <p>Should be self-explanatory.</p>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
329
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
330 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
331 ~/learn $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
332 /Users/fschmidt/learn
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
333 ~/learn $ cd ~
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
334 ~ $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
335 /Users/fschmidt
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
336 ~ $ cd learn/dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
337 ~/learn/dir1 $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
338 /Users/fschmidt/learn/dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
339 ~/learn/dir1 $ cd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
340 ~ $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
341 /Users/fschmidt
49
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
342 ~ $ cd ~/learn
46
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
343 ~/learn $ pwd
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
344 /Users/fschmidt/learn
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
345 ~/learn $ echo ~
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
346 /Users/fschmidt
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
347 ~/learn $ echo .
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
348 .
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
349 ~/learn $ echo ..
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
350 ..
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
351 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
352
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
353 <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
354
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
355 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
356 ~/learn $ ls -ltF
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
357 total 0
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
358 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
359 -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
360 -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
361 -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
362 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
363
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
364 <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
365
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
366 <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
367
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
368 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
369 ~/learn $ echo file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
370 file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
371 ~/learn $ echo file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
372 </code>
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>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
375 <%
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
376 end
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
377 }
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
378 files = {
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
379 title = [[Working with Files]]
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
380 content = function()
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
381 %>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
382 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
383 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
384 dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
385 ~/learn $ cp file1 copied
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
386 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
387 copied dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
388 ~/learn $ mv copied moved
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
389 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
390 dir1/ file1 file2 file3 moved
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
391 ~/learn $ rm moved
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 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
395
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
396 <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
397
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
398 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
399 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
400 dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
401 ~/learn $ mkdir dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
402 ~/learn $ touch dir2/d2file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
403 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
404 dir1/ dir2/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
405 ~/learn $ ls dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
406 d2file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
407 ~/learn $ rm dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
408 rm: dir2: is a directory
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
409 ~/learn $ rm -d dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
410 rm: dir2: Directory not empty
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
411 ~/learn $ rm dir2/d2file
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
412 ~/learn $ rm -d dir2
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 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
416
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
417 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
418 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
419 dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
420 ~/learn $ mkdir dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
421 ~/learn $ touch dir2/d2file
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/ dir2/ file1 file2 file3
47
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
424 ~/learn $ rm -r dir2
46
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
425 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
426 dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
427 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
428
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
429 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
430 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
431 dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
432 ~/learn $ cp dir1 dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
433 cp: dir1 is a directory (not copied).
47
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
434 ~/learn $ cp -r dir1 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/ dir2/ file1 file2 file3
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
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
439 ~/learn $ cp f* dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
440 ~/learn $ ls dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
441 d1file file1 file2 file3
47
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
442 ~/learn $ rm -r dir2
46
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
443 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
444 dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
445 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
446
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
447 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
448 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
449 dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
450 ~/learn $ mkdir dir2
47
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
451 ~/learn $ cp -r dir1 dir2
46
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
452 ~/learn $ ls -F dir2
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
453 dir1/
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
454 ~/learn $ ls -F dir2/dir1
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
455 d1file
47
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
456 ~/learn $ rm -r dir2
46
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
457 ~/learn $ ls -F
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
458 dir1/ file1 file2 file3
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
459 </code>
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 <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
462 <%
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
463 end
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
464 }
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
465 quote = {
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
466 title = [[Quoting]]
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
467 content = function()
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
468 %>
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
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
498 <code block>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
499 ~/learn $ echo $X
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
500
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
501 ~/learn $ X="some text"
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
502 ~/learn $ echo $X
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
503 some text
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
504 ~/learn $ echo "X is: $X"
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
505 X is: some text
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
506 ~/learn $ echo 'X is: $X'
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
507 X is: $X
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
508 ~/learn $ X="$X and more"
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
509 ~/learn $ echo $X
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
510 some text and more
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
511 </code>
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
512
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
513 <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
514
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
515 <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
516
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
517 <code block>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
518 ~/learn $ echo $PATH
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
519 /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
520 ~/learn $ which ls
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
521 /bin/ls
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
522 ~/learn $ cd /bin
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
523 /bin $ pwd
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
524 /bin
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
525 /bin $ ls
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
526 [ dd launchctl pwd test
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
527 bash df link rm unlink
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
528 cat echo ln rmdir wait4path
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
529 chmod ed ls sh zsh
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
530 cp expr mkdir sleep
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
531 csh hostname mv stty
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
532 dash kill pax sync
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
533 date ksh ps tcsh
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
534 /bin $ ls -F
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
535 [* dd* launchctl* pwd* test*
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
536 bash* df* link* rm* unlink*
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
537 cat* echo* ln* rmdir* wait4path*
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
538 chmod* ed* ls* sh* zsh*
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
539 cp* expr* mkdir* sleep*
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
540 csh* hostname* mv* stty*
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
541 dash* kill* pax* sync*
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
542 date* ksh* ps* tcsh*
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
543 /bin $ cd ~/learn
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
544 ~/learn $
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
545 </code>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
546
53
Franklin Schmidt <fschmidt@gmail.com>
parents: 50
diff changeset
547 <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 files.</p>
47
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
548
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
549 <code block>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
550 ~/learn $ subl file1
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
551 -bash: subl: command not found
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
552 ~/learn $ "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" file1
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
553 ~/learn $ PATH="$PATH:/Applications/Sublime Text.app/Contents/SharedSupport/bin"
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
554 ~/learn $ echo $PATH
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
555 /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
556 ~/learn $ subl file1
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
557 ~/learn $
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
558 </code>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
559
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
560 <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
561
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
562 <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
563
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
564 <code block>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
565 C:\Users\fschmidt>winword
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
566
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
567 C:\Users\fschmidt>where winword
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
568 C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
569 </code>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
570
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
571 <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
572
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
573 <code block>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
574 ~ $ winword
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
575 bash: winword: command not found
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
576 ~ $ echo $PATH
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
577 /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
578 ~ $ PATH="$PATH:/c/Program Files/Microsoft Office/root/Office16"
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
579 ~ $ echo $PATH
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
580 /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
581 ~ $ winword
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 </code>
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 <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
586
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
587 <code block>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
588 ~/learn $ open -a 'Sublime Text' file1
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
589 </code>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
590
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
591 <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
592
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
593 <code block>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
594 Franklins-MacBook-Pro:learn fschmidt$ echo $PS1
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
595 \h:\W \u\$
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
596 Franklins-MacBook-Pro:learn fschmidt$ PS1="\w $ "
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
597 ~/learn $ echo $PS1
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
598 \w $
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
599 ~/learn $
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
600 </code>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
601
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
602 <p>Google "bash PS1" for more info.</p>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
603
46
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
604 <%
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
605 end
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
606 }
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
607 bash_profile = {
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
608 title = [[.bash_profile]]
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
609 content = function()
89fdc29b296f learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
610 %>
47
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 ~/learn $ cd
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
613 ~ $ ls .bash_profile
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
614 .bash_profile
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
615 </code>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
616
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
617 <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
618
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
619 <code block>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
620 ~ $ # comment line, does nothing
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
621 ~ $ echo whatever # end of line comment
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
622 whatever
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 </code>
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 <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
627
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
628 <code block>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
629 ~ $ open -a 'Sublime Text' .bash_profile
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
630 </code>
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 <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
633
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
634 <code block>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
635 ~ $ notepad .bash_profile
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
636 </code>
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>Now try adding this line to <code>.bash_profile</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 <code block>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
641 echo hello there
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
642 </code>
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
643
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
644 <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
645
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
646 <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
647
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
648 <%
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
649 end
84dd3edd03e9 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
650 }
48
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
651 find = {
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
652 title = [[The "find" Command]]
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
653 content = function()
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
654 %>
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
655 <code block>
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
656 ~/learn $ find .
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
657 .
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
658 ./file3
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
659 ./file2
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
660 ./file1
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
661 ./dir1
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
662 ./dir1/d1file
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
663 ~/learn $ find . -name 'file*'
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
664 ./file3
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
665 ./file2
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
666 ./file1
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
667 ~/learn $ find . -name '*file'
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
668 ./dir1/d1file
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
669 ~/learn $ find . -name 'd*'
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
670 ./dir1
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
671 ./dir1/d1file
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
672 ~/learn $ find . -name '*1' -or -name '*2'
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
673 ./file2
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
674 ./file1
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
675 ./dir1
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
676 </code>
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
677
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
678 <p><code>find</code> recursively searches for files in a directory tree. Note that in this case the <code>*</code> wildcard matching is not being done by Bash, it is being done by <code>find</code>. <code>find</code> has many options for searching for files and acting on them, see <code>man find</code>.</p>
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
679 <%
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
680 end
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
681 }
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
682 io = {
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
683 title = [[Input and Output]]
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
684 content = function()
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
685 %>
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
686 <code block>
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
687 ~/learn $ echo 'this is a test' >test.txt
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
688 ~/learn $ ls -F
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
689 dir1/ file1 file2 file3 test.txt
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
690 ~/learn $ cat test.txt
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
691 this is a test
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
692 ~/learn $ echo 'this is another test' >test.txt
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
693 ~/learn $ cat test.txt
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
694 this is another test
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
695 ~/learn $ echo 'another line' >>test.txt
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
696 ~/learn $ cat test.txt
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
697 this is another test
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
698 another line
49
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
699 ~/learn $ cat &lt;test.txt
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
700 this is another test
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
701 another line
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
702 ~/learn $ cat &lt;&lt;End >test.txt
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
703 > I am typing this
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
704 > and this
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
705 > End
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
706 ~/learn $ cat test.txt
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
707 I am typing this
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
708 and this
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
709 ~/learn $ (echo one; echo two) >test.txt
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
710 ~/learn $ cat test.txt
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
711 one
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
712 two
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
713 </code>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
714
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
715 <p>All programs have standard input, standard output, and standard error. Programs write normal output to standard output and error messages to standard error. By default, standard input comes from the terminal, and standard output and standard error go to the terminal, but this can be changed. <code>>file</code> sends standard output to <code>file</code>. <code>>>file</code> appends standard output to <code>file</code>. <code>&lt;file</code> reads standard input from <code>file</code>. <code>&lt;&lt;whatever</code> reads standard input from the text that follows until a line with just <code>whatever</code>. Commands can be combined between <code>(</code> and <code>)</code>. Be sure to <code>man cat</code> to understand how <code>cat</code> works.</p>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
716
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
717 <code block>
48
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
718 ~/learn $ ls >ls.txt
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
719 ~/learn $ cat ls.txt
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
720 dir1
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
721 file1
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
722 file2
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
723 file3
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
724 ls.txt
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
725 test.txt
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
726 ~/learn $ ls -d f* q* >ls.txt
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
727 ls: q*: No such file or directory
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
728 ~/learn $ cat ls.txt
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
729 file1
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
730 file2
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
731 file3
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
732 ~/learn $ ls -d f* q* 2>ls.txt
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
733 file1 file2 file3
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
734 ~/learn $ cat ls.txt
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
735 ls: q*: No such file or directory
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
736 ~/learn $ ls -d f* q* | tee ls.txt
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
737 ls: q*: No such file or directory
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
738 file1
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
739 file2
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
740 file3
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
741 ~/learn $ cat ls.txt
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
742 file1
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
743 file2
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
744 file3
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
745 ~/learn $ ls -d f* q* 2>&1 | tee ls.txt
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
746 ls: q*: No such file or directory
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
747 file1
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
748 file2
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
749 file3
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
750 ~/learn $ cat ls.txt
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
751 ls: q*: No such file or directory
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
752 file1
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
753 file2
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
754 file3
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
755 </code>
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
756
49
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
757 <p><code>2>file</code> sends standard error to <code>file</code>. <code>|</code> sends standard output of the previous command to standard input of the following command. <code>2>&1</code> sends standard error to standard output. <code>tee file</code> reads standard input and then writes it to both standard output and to <code>file</code>.</p>
48
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
758
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
759 <code block>
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
760 ~/learn $ find . -type f | wc -l
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
761 6
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
762 </code>
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
763
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
764 <p>There are 6 files in <code>learn</code>. Use <code>man</code> to figure out how this works.</p>
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
765 <%
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
766 end
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
767 }
49
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
768 ctrl = {
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
769 title = [[Control Keys]]
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
770 content = function()
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
771 %>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
772 <code block>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
773 ~/learn $ sleep 3
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
774 ~/learn $ sleep 30
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
775 ^C
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
776 ~/learn $
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
777 </code>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
778
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
779 <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>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
780
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
781 <code block>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
782 ~/learn $ wc
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
783 I am typing this
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
784 and this
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
785 now I will end my input with control+d
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
786 3 14 65
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
787 ~/learn $ wc
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
788 this time I will use control+c to break out
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
789 ^C
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
790 ~/learn $
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
791 </code>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
792
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
793 <p>Control+d means end of input.</p>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
794 <%
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
795 end
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
796 }
48
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
797 subst = {
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
798 title = [[Command Substitution]]
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
799 content = function()
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
800 %>
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
801 <code block>
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
802 ~/learn $ echo I am in $(pwd)
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
803 I am in /Users/fschmidt/learn
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
804 ~/learn $ echo this directory contains: $(ls)
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
805 this directory contains: dir1 file1 file2 file3 ls.txt test.txt
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
806 ~/learn $ echo this directory contains $(ls | wc -l) files
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
807 this directory contains 6 files
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
808 </code>
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
809
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
810 <p><code>cmd $(commands)</code> will use the output of <code>commands</code> as argument text for <code>cmd</code>.</p>
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
811
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
812 <code block>
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
813 ~/learn $ cat $(find . -type f) | wc -c
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
814 86
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
815 </code>
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
816
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
817 <p>The files in <code>learn</code> contain a total of 86 bytes. Use <code>man</code> to figure out how this works.</p>
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
818 <%
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
819 end
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
820 }
49
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
821 ampersand = {
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
822 title = [[Ampersand]]
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
823 content = function()
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
824 %>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
825 <code block>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
826 ~/learn $ (sleep 5; echo done) &
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
827 [1] 10080
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
828 ~/learn $ echo waiting
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
829 waiting
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
830 ~/learn $ done
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
831
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
832 [1]+ Done ( sleep 5; echo done )
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
833 ~/learn $
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
834 </code>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
835
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
836 <p>Normally Bash waits for a command to complete before showing the command prompt and allowing input. But ending a command line with <code>&</code> tells bash not to wait, but instead to run the command in a separate process. Above in <code>~/learn $ echo waiting</code>, I typed in <code>echo waiting</code>. But in <code>~/learn $ done</code>, I did not type <code>done</code>. Instead this was produced by <code>echo done</code> after 5 seconds. <code>[1] 10080</code> tells me that a process was started and <code>[1]+ Done ( sleep 5; echo done )</code> tells me that the process finished.</p>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
837
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
838 <p>This is useful where you do not want to wait for a command to finish. Consider this on Windows:</p>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
839
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
840 <code block>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
841 ~ $ notepad
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
842 </code>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
843
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
844 <p>Here you will not get a command prompt again until you quit Notepad because Bash is waiting for this command to finish. So instead do:
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
845
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
846 <code block>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
847 ~ $ notepad &
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
848 [1] 2010
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
849 ~ $
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
850 </code>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
851
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
852 <p>Now Notepad will run and you can continue using Bash.</p>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
853 <%
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
854 end
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
855 }
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
856 scripts = {
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
857 title = [[Shell Scripts]]
41
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
858 content = function()
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
859 %>
49
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
860 <p>Make a file called <code>test.sh</code> containing the following:</p>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
861
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
862 <code block>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
863 echo this is a shell script
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
864 </code>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
865
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
866 <p>Now from Bash:</p>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
867
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
868 <code block>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
869 ~/learn $ cat test.sh
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
870 echo this is a shell script
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
871 ~/learn $ ./test.sh
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
872 -bash: ./test.sh: Permission denied
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
873 ~/learn $ ls -F test.sh
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
874 test.sh
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
875 ~/learn $ chmod +x test.sh
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
876 ~/learn $ ls -F test.sh
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
877 test.sh*
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
878 ~/learn $ ./test.sh
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
879 this is a shell script
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
880 ~/learn $
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
881 </code>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
882
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
883 <p><code>chmod +x file</code> makes <code>file</code> into an executable that can be run. Now I will edit <code>test.sh</code></p>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
884
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
885 <code block>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
886 ~/learn $ # edit test.sh
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
887 ~/learn $ cat test.sh
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
888 nonsense
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
889 echo this is a shell script
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
890 ~/learn $ ./test.sh
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
891 ./test.sh: line 1: nonsense: command not found
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
892 this is a shell script
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
893 ~/learn $ # edit test.sh
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
894 ~/learn $ cat test.sh
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
895 set -e
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
896 nonsense
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
897 echo this is a shell script
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
898 ~/learn $ ./test.sh
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
899 ./test.sh: line 2: nonsense: command not found
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
900 ~/learn $
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
901 </code>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
902
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
903 <p>By default, scripts continue running after an error. In longer scripts, we want the script to exit after an error. <code>set -e</code> does this, see <code>help set</code>.</p>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
904
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
905 <code block>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
906 ~/learn $ X=some
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
907 ~/learn $ echo $X
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
908 some
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
909 ~/learn $ echo $Xthing
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
910
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
911 ~/learn $ echo ${X}thing
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
912 something
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
913 ~/learn $ # edit test.sh
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
914 ~/learn $ cat test.sh
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
915 echo "\$* = $*"
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
916 echo "\$# = $#"
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
917 echo "\$0 = $0"
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
918 echo "\$1 = $1"
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
919 echo "\$2 = $2"
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
920 echo "\$3 = $3"
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
921 echo "\$4 = $4"
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
922 echo "\$14 = $14"
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
923 echo "\${14} = ${14}"
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
924 echo "\$@ = $@"
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
925 ./count.sh "$*"
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
926 ./count.sh "$@"
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
927 ~/learn $ ./test.sh a b "c d"
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
928 $* = a b c d
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
929 $# = 3
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
930 $0 = ./test.sh
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
931 $1 = a
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
932 $2 = b
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
933 $3 = c d
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
934 $4 =
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
935 $14 = a4
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
936 ${14} =
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
937 $@ = a b c d
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
938 1
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
939 3
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
940 ~/learn $ cat count.sh
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
941 echo $#
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
942 ~/learn $
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
943 </code>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
944
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
945 <p>Bash scripts have special defined variables. The difference between <code>$*</code> and <code>$@</code> is subtle, and you will usually just use <code>$*</code>. <code>$*</code> returns all arguments as one string while <code>$@</code> returns the arguments separately, but this distinction rarely makes any difference.</p>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
946 <%
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
947 end
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
948 }
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
949 vars_and_scripts = {
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
950 title = [[Variables and Scripts]]
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
951 content = function()
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
952 %>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
953 <code block>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
954 ~/learn $ X=value
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
955 ~/learn $ echo $X
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
956 value
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
957 ~/learn $ # edit test.sh
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
958 ~/learn $ cat test.sh
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
959 echo "\$X = $X"
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
960 ~/learn $ ./test.sh
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
961 $X =
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
962 ~/learn $ export X
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
963 ~/learn $ ./test.sh
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
964 $X = value
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
965 </code>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
966
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
967 <p>Variables are defined in the current shell. Shell scripts are run in their own shell. So by default, they don't see variables defined in the terminal/parent shell. <code>export var</code> makes <code>var</code> available in descendant processes, meaning available in shell scripts. It is a good idea to do <code>export PATH</code> in <code>.bash_profile</code> so that your PATH is available to your scripts.</p>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
968
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
969 <code block>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
970 ~/learn $ X=terminal
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
971 ~/learn $ echo $X
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
972 terminal
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
973 ~/learn $ # edit test.sh
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
974 ~/learn $ cat test.sh
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
975 X=script
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
976 export X
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
977 ~/learn $ ./test.sh
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
978 ~/learn $ echo $X
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
979 terminal
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
980 ~/learn $ . test.sh
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
981 ~/learn $ echo $X
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
982 script
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
983 </code>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
984
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
985 <p>You can export a variable from parent to children but not from children to parent. <code>. script</code> includes the text in the file <code>script</code> in the current shell. In this case, it is not run in a separate shell. This is the only way to have a script set variables in your terminal shell.</p>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
986
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
987 <code block>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
988 ~/learn $ pwd
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
989 /Users/fschmidt/learn
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
990 ~/learn $ # edit test.sh
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
991 ~/learn $ cat test.sh
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
992 cd ~
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
993 ~/learn $ ./test.sh
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
994 ~/learn $ pwd
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
995 /Users/fschmidt/learn
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
996 ~/learn $ . test.sh
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
997 ~ $ pwd
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
998 /Users/fschmidt
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
999 ~ $ cd learn
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1000 ~/learn $
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1001 </code>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1002
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1003 <p>This illustrates the difference between <code>./script</code> and <code>. script</code>.</p>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1004
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1005 <%
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1006 end
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1007 }
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1008 your_scripts = {
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1009 title = [[Your Scripts]]
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1010 content = function()
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1011 %>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1012 <code block>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1013 ~/learn $ echo $PATH
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1014 /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
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1015 ~/learn $ echo ~/Dropbox/bin
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1016 /Users/fschmidt/Dropbox/bin
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1017 ~/learn $ ls -F ~/Dropbox/bin/e
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1018 /Users/fschmidt/Dropbox/bin/e*
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1019 ~/learn $ cat ~/Dropbox/bin/e
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1020 open -a 'Sublime Text' $*
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1021 ~/learn $ e test.sh
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1022 ~/learn $
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1023 </code>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1024
53
Franklin Schmidt <fschmidt@gmail.com>
parents: 50
diff changeset
1025 <p>When you write useful scripts, put them in a directory and add that directory to your PATH. I use <code>~/Dropbox/bin</code> and I have a script named <code>e</code> in that directory for editing files. So <code>e test.sh</code> lets me edit <code>test.sh</code> from the command line.</p>
49
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1026 <%
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1027 end
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1028 }
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1029 advanced = {
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1030 title = [[Advanced Scripting]]
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1031 content = function()
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1032 %>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1033 <p>Here is a more advanced script called <code>undocx.sh</code> that unpacks a Word DOCX file.</p>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1034
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1035 <code block>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1036 #!/bin/bash
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1037
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1038 set -e
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1039
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1040 if [ $# -ne 1 ]; then
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1041 echo "usage: $0 filename"
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1042 exit 1
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1043 fi
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1044
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1045 FILE="$1"
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1046 NEWDIR=$(basename $FILE .docx)
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1047
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1048 mkdir $NEWDIR
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1049 unzip $FILE -d $NEWDIR
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1050
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1051 export XMLLINT_INDENT=$'\t'
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1052 for file in $(find $NEWDIR -name "*.xml" -o -name "*.rels"); do
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1053 mv "$file" temp.xml
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1054 xmllint --format temp.xml >"$file"
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1055 done
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1056 rm temp.xml
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1057 </code>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1058
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1059 <p>Bash is a full programming language containing all the usual features. Some commands in my script are well explained by <code>man</code>, but some are not. In particular, the documentation for <code>if</code> and <code>for</code> are poor. In cases like this, I suggest asking ChatGPT like this:
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1060
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1061 <code block>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1062 Please explain the Bash "if" statement.
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1063 </code>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1064
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1065 <code block>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1066 Please explain the Bash "for" statement.
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1067 </code>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1068
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1069 <p>ChatGPT knows Bash well. I trust ChatGPT to explain details but not to explain core concepts. You can also try Google, but ChatGPT is better than modern programmers.</p>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1070 <%
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1071 end
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1072 }
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1073 conclusion = {
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1074 title = [[Conclusion]]
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1075 content = function()
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1076 %>
3057adc065f3 finish learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
1077 <p>At least 90% of your usage of Bash will be simple commands that you enter in the terminal. Try to use Bash as much as possible instead of using the GUI so that you get practice using it. Unless you become system administrator, you won't use advanced scripting much. But with a solid understanding of the core basics, you should be able to figure out how to read or write advanced scripts when needed.</p>
41
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
1078 <%
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
1079 end
fbf2a8deee98 learn minor
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
1080 }
40
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1081 }
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1082
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1083
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1084 local function show_toc(content)
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1085 %>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1086 <ul>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1087 <%
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1088 for id, info in pairs(content) do
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1089 %>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1090 <li><a id="c_<%=id%>" href="#<%=id%>"><%=info.title%></a></li>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1091 <%
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1092 end
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1093 %>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1094 </ul>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1095 <%
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1096 end
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1097
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1098 local function show_content(content,h)
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1099 for id, info in pairs(content) do
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1100 %>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1101 <div heading>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1102 <h<%=h%>><a id="<%=id%>" href="#<%=id%>"><%=info.title%></a></h<%=h%>>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1103 <a href="#c_<%=id%>">contents</a>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1104 </div>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1105 <%
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1106 info.content()
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1107 end
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1108 end
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1109
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1110 return function()
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1111 Io.stdout = Http.response.text_writer()
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1112 %>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1113 <!doctype html>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1114 <html>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1115 <head>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1116 <% head() %>
45
14518d772090 start learn_bash
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
1117 <title>Reactionary Bash Tutorial</title>
40
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1118 </head>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1119 <body>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1120 <% header() %>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1121 <div content>
48
889e3c2d2699 learn_bash work
Franklin Schmidt <fschmidt@gmail.com>
parents: 47
diff changeset
1122 <h1><a href="learn_bash.html">Reactionary Bash Tutorial</a></h1>
40
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1123 <hr>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1124 <h2>Contents</h2>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1125 <div toc>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1126 <% show_toc(content) %>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1127 </div>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1128 <hr>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1129 <% show_content(content,2) %>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1130 </div>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1131 </body>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1132 </html>
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1133 <%
ebab99118e19 add learn.html
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1134 end