Sale!

測驗: Exercise 1

Original price was: $40.00.Current price is: $30.00.

Category:

Description

Rate this product

下午4:01 測驗: Exercise 1

Exercise 1

測驗說明
問題 1 100 分數
The goal of this exercise is to get you familiar with the terminal (command
line), which is a key part of Linux. This includes so-called Unix commands,
which are common commands understood by many terminal programs
across operating systems. Next lecture you will get to hear more about Unix,
which is Linux evolved from. You will also run a git command and use a shell
script, which are also common practice in the Linux world.
Let’s start by getting a terminal program up and running:
Get access to a terminal emulator
Windows – Use the terminal in WSL (Windows Subsystem for Linux), install
mobaXterm (https://mobaxterm.mobatek.net), or use some other terminal
emulator
Mac – Use the built-in terminal
Linux – Use the built-in terminal
Enter the text pwd into the prompt of the terminal and hit enter
This is how you run a Unix command
pwd is our Unix command in this case and means print working directory,
i.e., determining where you are in the file system
It will be at your home directory, which is where documents are typically
stored
Run the command cd ~
cd – change directory
~ – a shortcut for your home directory
Running the command pwd again will show that we changed to the home
directory, i.e., we didn’t go anywhere actually
Run mkdir gitrepos
mkdir – make a directory (folder)
gitrepos – the argument that the command uses as the folder name
Run ls
ls – list, i.e., list the files and folders in the current working directory
You should see the new gitrepos folder
Change the current working directory to the gitrepos folder using one of the
previously mentioned commands
2023/8/28 下午4:01 測驗: Exercise 1
https://canvas.rice.edu/courses/59111/quizzes/91244/take 2/4
Now let’s download a Wordle game that can be played in the terminal:
GitHub is a site known to provide an amazing amount of open-source code
There is a fun piece of code (link
(https://gist.github.com/6a1a6a7b34a0d0abcac00b47e3d01513.git) ) that
implements Wordle for the command line
Run git clone
https://gist.github.com/6a1a6a7b34a0d0abcac00b47e3d01513.git
git – a command to run the git version control system, which manages code
(including code changes)
clone – an argument telling git to download the code from the final argument
(which is a link to code on GitHub)
Run a previously mentioned Unix command to check that there is now a folder
in the gitrepos folder
Run another command to change into that new directory (which was
downloaded by the git command previously)
Run another command to show what files are in the downloaded directory
You should see two – one ends in .md (Markdown; a format for text files) and
one ends in .sh (shell; shell scripts can be run by the terminal)
In general (not just for shell scripts), the shell interprets and runs
commands given in the terminal
We want to run the shell script but it is not currently marked as executable, so
we need to do something to make it runnable
Run man chmod
man – manual, provides info about Unix commands
chmod – a Unix command that changes file properties (e.g., executability);
However, in this context the chmod command is being passed as an
argument for the man command, which means that we will be presented
with manual information about the chmod command
Hit the q key to exit the manual once you’ve read a few lines of the text
Run ls -al
-al is an argument that tells list to print things in more of a list fashion (l) and
to show all (a) files/folders [some will be hidden if this argument is
excluded]
Notice that there is something like -rw-r–r– next to wordle.sh
This string indicates that some users can read (r) and write (w), but
there is no x (execution)
Run chmod +x Wordle.sh
The +x argument tells chmod to make Wordle.sh executable
Try ls -al again and notice that we now have something like -rwxr-xr-x next
to wordle.sh
The x’s are showing that users can now execute the program
Since it is now executable, let’s do it – run ./wordle.sh
How to play: https://www.nytimes.com/games/wordle/index.html
2023/8/28 下午4:01 測驗: Exercise 1
https://canvas.rice.edu/courses/59111/quizzes/91244/take 3/4
上傳
Try a round or two for fun!
We can now run Wordle, but we want to be able to easily do it wherever we
want in the file system, just like how we can type pwd anytime and it will tell
us where we are; Let’s make this happen for Wordle:
Run echo $PATH
echo – print something to the terminal
$PATH – an “environmental variable” in the shell, with the name PATH
The PATH variable contains the directories that the shell looks at when
trying to execute a command like matlab – it needs to find the matlab
executable in one of these directories
We need to add the directory we downloaded to this variable so that we
can run Wordle from anywhere in the file system easily
Let’s go ahead and rename the folder containing wordle.sh to something
simpler using the next steps
Run cd ..
This moves you up one folder, so running ls should show the folder
downloaded by git
Run mv complexFolderName wordleDir [replacing complexFolderName with
that annoying folder name]
mv – move command, which can be used to rename folders if done in the
way above
Try ls now, the folder should have been renamed to wordleDir
cd to wordleDir
Run pwd
Run export PATH=$PATH:/Users/joe/git/wordleDir [replacing
/Users/joe/git/worldDir with whatever the last pwd command gave you]
export changes variables
In this case we are adding our new folder to the existing PATH variable
Change back to the home directory: run cd ~
Run pwd to verify that you are home
Run wordle.sh
You should be able to play the game anywhere in the file system now just
by running this command – cool!
You have completed the in-class exercise. Submit a screenshot of the last
two major bullet points – specifically, the terminal output of pwd followed by
wordle.sh output, both in one screenshot, with your username in your
terminal visible.
選擇檔案
2023/8/28 下午4:01 測驗: Exercise 1
https://canvas.rice.edu/courses/59111/quizzes/91244/take 4/4
測驗保存於 16:01 提交測驗

Reviews

There are no reviews yet.

Be the first to review “測驗: Exercise 1”

Your email address will not be published. Required fields are marked *