The readings for Monday, January 30 are:
You will need this information to complete this reading assignment.
You will need this information to complete the next homework assignment, but not for this reading assignment.
The focus of this reading is to introduce shell scripting in bash and some basic networking.
Optional Resources:
Given the following output of ls -l
:
total 8.0K -rw-r--r-- 1 pbui pbui 23 Jan 18 15:39 README.md -rw-r--r-- 1 pbui pbui 155 Jan 25 01:15 exists.sh
And the following script, exists.sh
:
#!/bin/sh if test -e "$1"; then echo "$1 exists!" else echo "$1 does not exist!" fi
In your reading02/README.md
file, answer the following questions:
How would you run the script even though it is not executable?
How would you make this script executable?
Once this script is executable, how would you run it directly?
What is the purpose of the line #!/bin/sh
?
What is the output of the script if you run it with the arguments *
?
What is the $1
that appears in the script?
What does test -e "$1"
do?
What does this script do?
Write a new version of exists.sh
with the following modifications:
Test every command line argument (one at a time).
Return an error code if one of the tests fails.
Display an error message and exit with an error if no arguments are given.
To verify the correctness of your exists.sh
script, you should be able to
reproduce the following:
$ ls -l # List files in reading02 directory total 8.0K -rw-r--r-- 1 pbui pbui 23 Jan 18 15:39 README.md -rwxr-xr-x 1 pbui pbui 254 Jan 28 18:02 exists.sh $ ./exists.sh * && echo Success # Run script and check error code exists.sh exists! README.md exists! Success $ ./exists.sh * ASDF || echo Success # Run script and check error code exists.sh exists! README.md exists! ASDF does not exist! Success
If you have any questions, comments, or concerns regarding the course, please provide your feedback at the end of your response.
To submit your assignment, please commit your work to the reading02
folder
in your assignments GitLab repository:
$ cd path/to/repository # Go to assignments repository $ cd reading02 # Go to Reading 02 directory ... $ $EDITOR README.md # Edit README.md $ git add README.md # Mark changes for commit $ git commit -m "reading02: README.md" # Record changes ... $ $EDITOR exists.sh # Edit exists shell script $ git add exists.sh # Mark changes for commit $ git commit -m "reading02: exists.sh" # Record changes ... $ git push # Send changes to GitLab