diff src/learn_bash.html.luan @ 48:889e3c2d2699

learn_bash work
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 07 Jan 2024 02:34:44 -0700
parents 84dd3edd03e9
children 3057adc065f3
line wrap: on
line diff
--- a/src/learn_bash.html.luan	Sat Jan 06 21:28:44 2024 -0700
+++ b/src/learn_bash.html.luan	Sun Jan 07 02:34:44 2024 -0700
@@ -655,6 +655,128 @@
 <%
 		end
 	}
+	find = {
+		title = [[The "find" Command]]
+		content = function()
+%>
+<code block>
+~/learn $ find .
+.
+./file3
+./file2
+./file1
+./dir1
+./dir1/d1file
+~/learn $ find . -name 'file*'
+./file3
+./file2
+./file1
+~/learn $ find . -name '*file'
+./dir1/d1file
+~/learn $ find . -name 'd*'
+./dir1
+./dir1/d1file
+~/learn $ find . -name '*1' -or -name '*2'
+./file2
+./file1
+./dir1
+</code>
+
+<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>
+<%
+		end
+	}
+	io = {
+		title = [[Input and Output]]
+		content = function()
+%>
+<code block>
+~/learn $ echo 'this is a test' >test.txt
+~/learn $ ls -F
+dir1/		file1		file2		file3		test.txt
+~/learn $ cat test.txt
+this is a test
+~/learn $ echo 'this is another test' >test.txt
+~/learn $ cat test.txt
+this is another test
+~/learn $ echo 'another line' >>test.txt 
+~/learn $ cat test.txt 
+this is another test
+another line
+~/learn $ ls >ls.txt
+~/learn $ cat ls.txt
+dir1
+file1
+file2
+file3
+ls.txt
+test.txt
+~/learn $ ls -d f* q* >ls.txt
+ls: q*: No such file or directory
+~/learn $ cat ls.txt
+file1
+file2
+file3
+~/learn $ ls -d f* q* 2>ls.txt
+file1	file2	file3
+~/learn $ cat ls.txt
+ls: q*: No such file or directory
+~/learn $ ls -d f* q* | tee ls.txt
+ls: q*: No such file or directory
+file1
+file2
+file3
+~/learn $ cat ls.txt
+file1
+file2
+file3
+~/learn $ ls -d f* q* 2>&1 | tee ls.txt
+ls: q*: No such file or directory
+file1
+file2
+file3
+~/learn $ cat ls.txt
+ls: q*: No such file or directory
+file1
+file2
+file3
+</code>
+
+<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 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>2>file</code> sends standard error to <code>file</code>.  <code>2>&1</code> sends standard error to standard output.  <code>|</code> sends standard output of the previous command to standard input of the following command.  We haven't used standard input before, but <code>tee file</code> reads standard input and then writes it to both standard output and to <code>file</code>.  And for completeness, <code>&lt;file</code> reads standard input from <code>file</code> even though I haven't shown an example of this.</p>
+
+<code block>
+~/learn $ find . -type f | wc -l
+       6
+</code>
+
+<p>There are 6 files in <code>learn</code>.  Use <code>man</code> to figure out how this works.</p>
+<%
+		end
+	}
+	subst = {
+		title = [[Command Substitution]]
+		content = function()
+%>
+<code block>
+~/learn $ echo I am in $(pwd)
+I am in /Users/fschmidt/learn
+~/learn $ echo this directory contains: $(ls)
+this directory contains: dir1 file1 file2 file3 ls.txt test.txt
+~/learn $ echo this directory contains $(ls | wc -l) files
+this directory contains 6 files
+</code>
+
+<p><code>cmd $(commands)</code> will use the output of <code>commands</code> as argument text for <code>cmd</code>.</p>
+
+<code block>
+~/learn $ cat $(find . -type f) | wc -c
+      86
+</code>
+
+<p>The files in <code>learn</code> contain a total of 86 bytes.  Use <code>man</code> to figure out how this works.</p>
+<%
+		end
+	}
 	later = {
 		title = [[placeholder]]
 		content = function()
@@ -704,7 +826,7 @@
 	<body>
 <%		header() %>
 		<div content>
-			<h1><a href="learn.html">Reactionary Bash Tutorial</a></h1>
+			<h1><a href="learn_bash.html">Reactionary Bash Tutorial</a></h1>
 			<hr>
 			<h2>Contents</h2>
 			<div toc>