changeset 47:84dd3edd03e9

learn_bash work
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 06 Jan 2024 21:28:44 -0700
parents 89fdc29b296f
children 889e3c2d2699
files src/learn_bash.html.luan src/site.css
diffstat 2 files changed, 151 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/learn_bash.html.luan	Fri Jan 05 20:58:57 2024 -0700
+++ b/src/learn_bash.html.luan	Sat Jan 06 21:28:44 2024 -0700
@@ -371,7 +371,6 @@
 		title = [[Working with Files]]
 		content = function()
 %>
-<p></p>
 <code block>
 ~/learn $ ls -F
 dir1/	file1	file2	file3
@@ -407,8 +406,6 @@
 dir1/	file1	file2	file3
 </code>
 
-<p></p>
-
 <code block>
 ~/learn $ ls -F
 dir1/	file1	file2	file3
@@ -416,19 +413,17 @@
 ~/learn $ touch dir2/d2file
 ~/learn $ ls -F
 dir1/	dir2/	file1	file2	file3
-~/learn $ rm -R dir2
+~/learn $ rm -r dir2
 ~/learn $ ls -F
 dir1/	file1	file2	file3
 </code>
 
-<p></p>
-
 <code block>
 ~/learn $ ls -F
 dir1/	file1	file2	file3
 ~/learn $ cp dir1 dir2
 cp: dir1 is a directory (not copied).
-~/learn $ cp -R dir1 dir2
+~/learn $ cp -r dir1 dir2
 ~/learn $ ls -F
 dir1/	dir2/	file1	file2	file3
 ~/learn $ ls dir2
@@ -436,23 +431,21 @@
 ~/learn $ cp f* dir2
 ~/learn $ ls dir2
 d1file	file1	file2	file3
-~/learn $ rm -R dir2
+~/learn $ rm -r dir2
 ~/learn $ ls -F
 dir1/	file1	file2	file3
 </code>
 
-<p></p>
-
 <code block>
 ~/learn $ ls -F
 dir1/	file1	file2	file3
 ~/learn $ mkdir dir2
-~/learn $ cp -R dir1 dir2
+~/learn $ cp -r dir1 dir2
 ~/learn $ ls -F dir2
 dir1/
 ~/learn $ ls -F dir2/dir1
 d1file
-~/learn $ rm -R dir2
+~/learn $ rm -r dir2
 ~/learn $ ls -F
 dir1/	file1	file2	file3
 </code>
@@ -465,7 +458,6 @@
 		title = [[Quoting]]
 		content = function()
 %>
-<p></p>
 
 <code block>
 ~/learn $ echo a   b
@@ -494,7 +486,6 @@
 		title = [[Variables]]
 		content = function()
 %>
-<p></p>
 
 <code block>
 ~/learn $ echo $X
@@ -512,6 +503,96 @@
 </code>
 
 <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>
+
+<p>There are special variables called environment variables that are used by Bash.</p>
+
+<code block>
+~/learn $ echo $PATH
+/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
+~/learn $ which ls
+/bin/ls
+~/learn $ cd /bin
+/bin $ pwd
+/bin
+/bin $ ls
+[		dd		launchctl	pwd		test
+bash		df		link		rm		unlink
+cat		echo		ln		rmdir		wait4path
+chmod		ed		ls		sh		zsh
+cp		expr		mkdir		sleep
+csh		hostname	mv		stty
+dash		kill		pax		sync
+date		ksh		ps		tcsh
+/bin $ ls -F
+[*		dd*		launchctl*	pwd*		test*
+bash*		df*		link*		rm*		unlink*
+cat*		echo*		ln*		rmdir*		wait4path*
+chmod*		ed*		ls*		sh*		zsh*
+cp*		expr*		mkdir*		sleep*
+csh*		hostname*	mv*		stty*
+dash*		kill*		pax*		sync*
+date*		ksh*		ps*		tcsh*
+/bin $ cd ~/learn
+~/learn $ 
+</code>
+
+<p><code>PATH</code> is an environment variable containing a list of directories separated by <code>:</code> that are searched for commands by Bash.  The <code>which</code> command shows the full path to a command.  <code>ls -F</code> appends a <code>*</code> to executable commands.</p>
+
+<code block>
+~/learn $ subl file1
+-bash: subl: command not found
+~/learn $ "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" file1
+~/learn $ PATH="$PATH:/Applications/Sublime Text.app/Contents/SharedSupport/bin"
+~/learn $ echo $PATH
+/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
+~/learn $ subl file1
+~/learn $ 
+</code>
+
+<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>
+
+<p>I have Microsoft Word on Windows.  From the Windows Command Prompt (not Bash):</p>
+
+<code block>
+C:\Users\fschmidt>winword
+
+C:\Users\fschmidt>where winword
+C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE
+</code>
+
+<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>
+
+<code block>
+~ $ winword
+bash: winword: command not found
+~ $ echo $PATH
+/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
+~ $ PATH="$PATH:/c/Program Files/Microsoft Office/root/Office16"
+~ $ echo $PATH
+/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
+~ $ winword
+~ $
+</code>
+
+<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>
+
+<code block>
+~/learn $ open -a 'Sublime Text' file1
+</code>
+
+<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>
+
+<code block>
+Franklins-MacBook-Pro:learn fschmidt$ echo $PS1
+\h:\W \u\$
+Franklins-MacBook-Pro:learn fschmidt$ PS1="\w $ "
+~/learn $ echo $PS1
+\w $
+~/learn $ 
+</code>
+
+<p>Google "bash PS1" for more info.</p>
+
 <%
 		end
 	}
@@ -519,7 +600,58 @@
 		title = [[.bash_profile]]
 		content = function()
 %>
-<p>later</p>
+<code block>
+~/learn $ cd
+~ $ ls .bash_profile 
+.bash_profile
+</code>
+
+<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>
+
+<code block>
+~ $ # comment line, does nothing
+~ $ echo whatever # end of line comment
+whatever
+~ $ 
+</code>
+
+<p>To edit <code>.bash_profile</code> on a Mac, you can do:</p>
+
+<code block>
+~ $ open -a 'Sublime Text' .bash_profile
+</code>
+
+<p>To edit <code>.bash_profile</code> on Windows, you can do:</p>
+
+<code block>
+~ $ notepad .bash_profile
+</code>
+
+<p>Now try adding this line to <code>.bash_profile</code>:</p>
+
+<code block>
+echo hello there
+</code>
+
+<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>
+
+<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>
+
+<%
+		end
+	}
+	ctrl_c = {
+		title = [[Control+c]]
+		content = function()
+%>
+<code block>
+~/learn $ sleep 3
+~/learn $ sleep 30
+^C
+~/learn $ 
+</code>
+
+<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>
 <%
 		end
 	}
--- a/src/site.css	Fri Jan 05 20:58:57 2024 -0700
+++ b/src/site.css	Sat Jan 06 21:28:44 2024 -0700
@@ -43,12 +43,15 @@
 
 code {
 	background-color: #DDD;
-	white-space: pre;
+	white-space: pre-wrap;
+	word-wrap: break-word;
 	padding: 2px;
 }
 code[block] {
 	display: block;
 	padding: 1em;
+	margin-top: 1em;
+	margin-bottom: 1em;
 }
 code[block]:first-line {
 	line-height: 0;