Skip to content

Solved the ids for the symbols $ to ? for basic shell commands fixes issue #358 #361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
201 changes: 81 additions & 120 deletions source/sec_dev_basic_shell_commands.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,19 @@
</p>
</introduction>

<subsection xml:id="subsec-files_directories_privileges">
<title>Files, Directories, and Privileges</title>
<p>
This and subsequent subsections are written to be followed as an extended exercise with explanations given as we go.
</p>
<exercise xml:id="exercise-try-cli">
<subsection xml:id="subsec-intro_shell_commands">
<title>Introduction to Shell Commands</title>
<exercise xml:id="exercise-try-cli">
<title>Exercise: Try shell commands for navigation</title>

<p>Try each of the following commands on your own machine.</p>
</exercise>
<p>
First, follow the directions given in <xref ref="subsec-getting_terminal"/> to open a terminal window so you can use your shell. All of the shell commands will be typed in this terminal window.
</p>
<paragraphs>
<title>Introduction to Shell Commands</title>
<p>
This and subsequent subsections are written to be followed as an extended exercise with explanations given as we go.
</p>
<p>
This section is written to be followed as an extended exercise with explanations given as we go.
</p>
<p>
</p>
<p>
Expand Down Expand Up @@ -94,9 +93,9 @@
<p>
The reason you see something like this is because the SHELL environment variable stores the location of the shell program. This location, called the <term>file path</term>, is given in the form of the path needed to find the location. We explore how this path is described in the next section.
</p>
</subsection>

</paragraphs>
<paragraphs>
<subsection xml:id="subsec-files_and_file_systems">
<title>Files and File Systems</title>
<p>
</p>
Expand Down Expand Up @@ -156,9 +155,9 @@
<p>
You should see a listing of files and directories.
</p>
</subsection>

</paragraphs>
<paragraphs>
<subsection xml:id="subsec-shell_command_options">
<title>Shell Command Options</title>
<p>
</p>
Expand Down Expand Up @@ -187,10 +186,10 @@ lrwxrwxrwx 1 root root 7 Mar 24 2022 bin -> usr/bin

<p>
Thus, the <c>-l</c> flag changed how the listing is displayed.
</p>
</paragraphs>
<paragraphs>
</p>
</subsection>

<subsection xml:id="subsec-file_permissions">
<title>File Permissions</title>
<p>

Expand Down Expand Up @@ -219,9 +218,9 @@ lrwxrwxrwx 1 root pearcej 7 Mar 24 2022 bin -> usr/bin
<p>
Occasionally, you need to change permissions of a file. For example, you might need to change permissions to make a file executable. Changing file permissions is done with the <c>chmod</c> command. We will explore this in a bit.
</p>
</paragraphs>
</subsection>

<paragraphs>
<subsection xml:id="subsec-command_options">
<title>Learning More About Command Options</title>
<p>
</p>
Expand All @@ -242,8 +241,8 @@ lrwxrwxrwx 1 root pearcej 7 Mar 24 2022 bin -> usr/bin
<pre>
ls -lra
</pre>
</paragraphs>
<paragraphs>
</subsection>
<subsection xml:id="subsec-creating_removing_directories">
<title>Creating and Removing Directories</title>
<p>
</p>
Expand Down Expand Up @@ -333,8 +332,8 @@ lrwxrwxrwx 1 root pearcej 7 Mar 24 2022 bin -> usr/bin
pwd
</pre>

</paragraphs>
<paragraphs>
</subsection>
<subsection xml:id="subsec-input_output_redirection">
<title>Input and Output Redirection</title>
<p>
</p>
Expand Down Expand Up @@ -484,9 +483,9 @@ wc -w &lt; temp.txt
Try it! This is an improvement because it is faster and avoids the use of a temporary file.
</p>

</paragraphs>
</subsection>

<paragraphs>
<subsection xml:id="subsec-scripts">
<title>Scripts</title>
<p>

Expand Down Expand Up @@ -546,9 +545,9 @@ wc -w &lt; temp.txt
chmod +x hellouser.sh
./hellouser.sh
</pre>
</paragraphs>
</subsection>

<paragraphs>
<subsection xml:id="subsec-file_management">
<title>File Management</title>
<p>
</p>
Expand Down Expand Up @@ -614,21 +613,19 @@ rm -i newfile4.txt
<p>
And, if you respond with "n", then the removal will not happen.
</p>
</paragraphs>
<paragraphs>
</subsection>
<subsection xml:id="subsec-shell_commands">
<title>A few time-saving shell commands</title>
<p>

</p>
<p>
The <em>up arrow</em> key retrieves the previous shell command. If you press it multiple times, it will take you back through multiple commands in your shell history. This is a useful way to repeat a command. For example, if you had a typo, you can use the up arrow, edit the command, and push enter to fix the command. Analogously, the <em>down arrow</em> will move you in the reverse direction through the shell command history. For more useful shell commands, type <c>man bash</c> for hints on how to search your shell history, re-execute commands, and much more.
</p>
<p>
The <em>up arrow</em> key retrieves the previous shell command. If you press it multiple times, it will take you back through multiple commands in your shell history. This is a useful way to repeat a command. For example, if you had a typo, you can use the up arrow, edit the command, and push enter to fix the command. Analogously, the <em>down arrow</em> will move you in the reverse direction through the shell command history. For more useful shell commands, type <c>man bash</c> for hints on how to search your shell history, re-execute commands, and much more.
</p>
<p>
An additional efficiency-enhancing feature is the <term>history</term> command. This command conveniently presents a record of previously executed shell commands, enabling users to effortlessly revisit their command history.
An additional efficiency-enhancing feature is the <term>history</term> command. This command conveniently presents a record of previously executed shell commands, enabling users to effortlessly revisit their command history.
</p>
<p>
Here's an example of what might be displayed when the <c>history</c> command is executed:
Here's an example of what might be displayed when the <c>history</c> command is executed:
</p>
<pre>
1 git init
Expand All @@ -639,9 +636,8 @@ And, if you respond with "n", then the removal will not happen.
6 history
</pre>

<p>
<p>
This paragraph is intended to alert you to some useful search features. A couple examples of very common search patterns are using wildcards for zero or more characters or for a single character. The asterisk (*) specifies zero or more characters to match. In bash the question mark (?) is used for matching exactly one single character.
</p>
<notation>
<usage><m>*</m></usage>
<description>asterisk - wildcard for zero or more characters</description>
Expand All @@ -650,116 +646,81 @@ And, if you respond with "n", then the removal will not happen.
<usage><m>?</m></usage>
<description>question mark - wildcard for single character</description>
</notation>
</p>
<p>
For example, if we type the following:
</p>
<pre>
</p> <p>
For example, if we type the following:
</p>
<pre>
rm -i newfile?.txt
</pre>
<p>
<p>
Then the question mark will match with any single character, and we will see the following prompts:
</p>
<pre>
<pre>
rm: remove regular file 'newfile2.txt'?
rm: remove regular file 'newfile4.txt'?
</pre>
<p>
<p>
If we instead type:
</p>
<pre>
<pre>
rm -i newfile*.txt
</pre>
<p>
</pre>
<p>
Then the asterisk will match with any number of characters (including zero), and we will see the following prompts:
</p>
<pre>
<pre>
rm: remove regular file 'newfile2.txt'?
rm: remove regular file 'newfile4.txt'?
rm: remove regular file 'newfile2_cp.txt'?
</pre>
<p>
As you can see, these search patterns give you a lot of power and control.
</p>
</paragraphs>

</subsection>

<conclusion>
<title>Conclusion</title>
<p>
Hopefully, you now feel a bit more comfortable using the shell. The shell commands discussed above are summarized in Appendix <xref ref="ap_shell_cheat_sheet"/>.
As you can see, these search patterns give you a lot of power and control.
</p>
</conclusion>

<exercise label = "basicShellCommands" numbered = "yes" language = "natural" adaptive="yes">

<exercise xml:id="quiz_basic_shell_commands">
<title>Quiz: Basic Shell Commands</title>
<statement>
<p>
You have a file named <term>data.txt</term> that contains the following lines:
</p>
<pre>apple
<p>
You have a file named <term>data.txt</term> that contains the following lines:
</p>
<pre>apple
orange
banana
grape
</pre>
<p>
Your task is to create a new file named <term>fruits.txt</term> and copy the contents of <term>data.txt</term> to <term>fruits.txt</term>. Next, append the word <c>kiwi</c> to <term>fruits.txt</term>. Then, display the contents of <term>fruits.txt</term> in the terminal. Next, count the number of fruits in <term>fruits.txt</term> and display the total count. Finally, overwrite the content of <term>data.txt</term> with the content of <term>fruits.txt</term> and rename <term>data.txt</term> to a new file named <c>fruits2</c>.
</p>
<p>
Here are some commands you may need to perform the task. Rearrange the correct commands in the correct order by dragging and dropping.
</p>
</pre>
<p>
Your task is to create a new file named <term>fruits.txt</term> and copy the contents of <term>data.txt</term> to <term>fruits.txt</term>. Next, append the word <c>kiwi</c> to <term>fruits.txt</term>. Then, display the contents of <term>fruits.txt</term> in the terminal. Next, count the number of fruits in <term>fruits.txt</term> and display the total count. Finally, overwrite the content of <term>data.txt</term> with the content of <term>fruits.txt</term> and rename <term>data.txt</term> to a new file named <c>fruits2</c>.
</p>
<p>
Here are some commands you may need to perform the task. Rearrange the correct commands in the correct order by dragging and dropping.
</p>
</statement>
<blocks>
<block order="1">
<choice correct = "yes">
<p>
<c>cat data.txt &gt; fruits.txt</c>
</p>
</choice>
<choice>
<p>
<c>cat data.txt &gt;&gt; fruits.txt</c>
</p>
</choice>
</block>
<block order="2">
<p>
<c>echo "kiwi" &gt;&gt; fruits.txt</c>
</p>
</block>
<block order="3">
<p>
<c>cat fruits.txt</c>
</p>
</block>
<block order ="4">
<choice>
<p>
<c>wc -l &lt; fruits.txt</c>
</p>
</choice>
<choice correct = "yes">
<p>
<c>wc -w &lt; fruits.txt</c>
</p>
</choice>
</block>
<block order="5">
<block order="1">
<choice correct="yes">
<p>
<c>cp -i fruits.txt data.txt </c>
<c>cat data.txt &gt; fruits.txt</c>
</p>
</block>
<block order="6">
</choice>
<choice>
<p>
<c>mv data.txt fruits2.txt</c>
<c>cat data.txt &gt;&gt; fruits.txt</c>
</p>
</block>
<block correct="no">
<p>
<c>rm data.txt fruits2.txt</c>
</p>
</block>
</choice>
</block>
</blocks>
</exercise>
</section>

</subsection>




<conclusion>
<title>Conclusion</title>
<p>
Hopefully, you now feel a bit more comfortable using the shell. The shell commands discussed above are summarized in Appendix <xref ref="ap_shell_cheat_sheet"/>.
</p>
</conclusion>
</section>