changeset 45:14518d772090

start learn_bash
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 05 Jan 2024 01:34:32 -0700
parents 5b4d5cf453a8
children 89fdc29b296f
files src/learn.html.luan src/learn_bash.html.luan src/site.css
diffstat 3 files changed, 230 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
diff -r 5b4d5cf453a8 -r 14518d772090 src/learn.html.luan
--- a/src/learn.html.luan	Thu Jan 04 18:27:05 2024 -0700
+++ b/src/learn.html.luan	Fri Jan 05 01:34:32 2024 -0700
@@ -49,15 +49,7 @@
 %>
 <p><a href="bash.html">Bash</a> is the other basic tool for reactionary programmers.  Learning Bash requires both reading, to understand the concepts, and practice.  Try to use Bash as much as possible instead of using the GUI so that you get practice using it.</p>
 
-<p>How you access Bash depends on your operating system.  If you are using Linux then you get Bash by default.  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>
-
-<p>This lesson will be based on two books: <a href="https://www.amazon.com/Mac-OS-Command-Line-Under/dp/0782143547/">The Mac OS X Command Line</a> and <a href="https://www.amazon.com/Shell-Programming-Unix-Linux-Developers/dp/0134496000/">Shell Programming in Unix, Linux and OS X</a>.  If you are on Linux, you may want to read <a href="https://www.amazon.com/Linux-Command-Line-2nd-Introduction/dp/1593279523/">The Linux Command Line</a>, but I won't be covering that here.  I will read the two books I recommended myself and make comments here as I read them.</p>
-
-<p>Comments on <a href="https://www.amazon.com/Mac-OS-Command-Line-Under/dp/0782143547/">The Mac OS X Command Line</a>:
-<ul>
-	<li>Chapter 1 -  Guided Tour of the Command Line.  Mac Finder = Windows File Explorer.  Mac command <code>open .</code> = Windows command <code>explorer .</code>.</li>
-</ul>
-</p>
+<p>I was hoping to just reference existing Bash tutorials in this lesson, but they are all horrible, so I am writing my own.  So for this lesson, read <a href="learn_bash.html">my tutorial</a> which is currently a work in progress.</p>
 <%
 		end
 	}
@@ -146,28 +138,6 @@
 	<head>
 <%		head() %>
 		<title>Learn Reactionary Programming</title>
-		<style>
-			div[toc] ul {
-				list-style-type: none;
-			}
-			div[toc] > ul {
-				padding-left: 0;
-			}
-			div[toc] > ul > li {
-				margin-bottom: 16px;
-			}
-			div[heading] {
-				display: flex;
-				justify-content: space-between;
-				margin-top: 36px;
-			}
-			div[heading] > * {
-				margin: 0;
-			}
-			div[heading] > a {
-				font-size: 14px;
-			}
-		</style>
 	</head>
 	<body>
 <%		header() %>
diff -r 5b4d5cf453a8 -r 14518d772090 src/learn_bash.html.luan
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/learn_bash.html.luan	Fri Jan 05 01:34:32 2024 -0700
@@ -0,0 +1,200 @@
+local Luan = require "luan:Luan.luan"
+local error = Luan.error
+local pairs = Luan.pairs or error()
+local Io = require "luan:Io.luan"
+local Http = require "luan:http/Http.luan"
+local Shared = require "site:/lib/Shared.luan"
+local head = Shared.head or error()
+local header = Shared.header or error()
+
+
+local content = {
+	intro = {
+		title = [[Introduction]]
+		content = function()
+%>
+<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 damn thing.</p>
+
+<p>I will focus on Mac and Windows.  I don't have Linux, and I hate Linux, so I won't discuss it.  Most of Bash is the same on Mac and Windows, but where they differ, I will discuss both.</p>
+<%
+		end
+	}
+	access = {
+		title = [[Running Bash]]
+		content = function()
+%>
+<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>
+<%
+		end
+	}
+	start = {
+		title = [[Getting Started]]
+		content = function()
+%>
+<p>When I start Bash on my Mac I see:</p>
+
+<code block>
+Last login: Thu Jan  4 23:25:35 on ttys004
+
+The default interactive shell is now zsh.
+To update your account to use zsh, please run `chsh -s /bin/zsh`.
+For more details, please visit https://support.apple.com/kb/HT208050.
+~ $ 
+
+</code>
+
+<p>On Windows - MSYS2 I just see:</p>
+
+<code block>
+~ $ 
+
+</code>
+
+<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>
+
+<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>
+
+<code block>
+~ $ qqq
+-bash: qqq: command not found
+~ $ 
+</code>
+
+<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>
+
+<code block>
+~ $ echo hi
+hi
+~ $ echo how are you
+how are you
+~ $ echo bye
+bye
+</code>
+
+<p>The <code>echo</code> command just echos what comes after.  Now press the up-arrow on your keyboard.  This should put the previous command where your cursor is.  Up-arrow again brings the command before that.  Try down-arrow and left-arrow and right-arrow.  You can use this to navigate through your command history.  The delete key also works for editing lines.  And of course you can type.  When you press return/enter then Bash will get your edited command and process it.</p>
+
+<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>
+
+<code block>
+~ $ echo how  are         you
+how are you
+</code>
+
+<p><code>echo</code> just returns the arguments separated by one space.</p>
+<%
+		end
+	}
+	man = {
+		title = [[The "man" Command]]
+		content = function()
+%>
+<p>Enter:</p>
+<code block>
+~ $ man echo
+</code>
+
+<p>You should get:</p>
+
+<code block>
+
+ECHO(1)                   BSD General Commands Manual                  ECHO(1)
+
+NAME
+     echo -- write arguments to the standard output
+
+SYNOPSIS
+     echo [-n] [string ...]
+
+DESCRIPTION
+     The echo utility writes any specified operands, separated by single blank
+     (` ') characters and followed by a newline (`\n') character, to the stan-
+     dard output.
+
+     The following option is available:
+
+     -n    Do not print the trailing newline character.  This may also be
+           achieved by appending `\c' to the end of the string, as is done by
+           iBCS2 compatible systems.  Note that this option as well as the
+           effect of `\c' are implementation-defined in IEEE Std 1003.1-2001
+           (``POSIX.1'') as amended by Cor. 1-2002.  Applications aiming for
+           maximum portability are strongly encouraged to use printf(1) to
+           suppress the newline character.
+:
+</code>
+
+<p>But if you are on Windows, you may not have <code>man</code> installed.  In that case, do:</p>
+
+<code block>
+~ $ pacman -S man-db
+</code>
+
+<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>
+
+<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>
+
+<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>
+<%
+		end
+	}
+	later = {
+		title = [[placeholder]]
+		content = function()
+%>
+<p>later</p>
+<%
+		end
+	}
+}
+
+
+local function show_toc(content)
+%>
+			<ul>
+<%
+	for id, info in pairs(content) do
+%>
+				<li><a id="c_<%=id%>" href="#<%=id%>"><%=info.title%></a></li>
+<%
+	end
+%>
+			</ul>
+<%
+end
+
+local function show_content(content,h)
+	for id, info in pairs(content) do
+%>
+			<div heading>
+				<h<%=h%>><a id="<%=id%>" href="#<%=id%>"><%=info.title%></a></h<%=h%>>
+				<a href="#c_<%=id%>">contents</a>
+			</div>
+<%
+		info.content()
+	end
+end
+
+return function()
+	Io.stdout = Http.response.text_writer()
+%>
+<!doctype html>
+<html>
+	<head>
+<%		head() %>
+		<title>Reactionary Bash Tutorial</title>
+	</head>
+	<body>
+<%		header() %>
+		<div content>
+			<h1><a href="learn.html">Reactionary Bash Tutorial</a></h1>
+			<hr>
+			<h2>Contents</h2>
+			<div toc>
+<%			show_toc(content) %>
+			</div>
+			<hr>
+<%			show_content(content,2) %>
+		</div>
+	</body>
+</html>
+<%
+end
diff -r 5b4d5cf453a8 -r 14518d772090 src/site.css
--- a/src/site.css	Thu Jan 04 18:27:05 2024 -0700
+++ b/src/site.css	Fri Jan 05 01:34:32 2024 -0700
@@ -45,3 +45,32 @@
 	background-color: #EEE;
 	padding: 2px;
 }
+code[block] {
+	white-space: pre;
+	display: block;
+	padding: 1em;
+}
+code[block]:first-line {
+	line-height: 0;
+}
+
+div[toc] ul {
+	list-style-type: none;
+}
+div[toc] > ul {
+	padding-left: 0;
+}
+div[toc] > ul > li {
+	margin-bottom: 16px;
+}
+div[heading] {
+	display: flex;
+	justify-content: space-between;
+	margin-top: 36px;
+}
+div[heading] > * {
+	margin: 0;
+}
+div[heading] > a {
+	font-size: 14px;
+}