Create a new directory called
Look up the
manprogram is your friend.
touchto create a new file called
# cd /tmp/missing/ && touch semester touch /tmp/missing/semester
Write the following into that file, one line at a time.
# Use the > redirection symbol and >> to append the second line echo '#!/bin/sh' > semester echo 'curl --head --silent https://missing.csail.mit.edu' >> semester
The history expansion character, usually
i, must be quoted to prevent history expansion.
''treats the contents inside as literal value, it won’t change anything.
""preserves the literal value of all characters within the quotes, with the exception of
",or newline.See here
Try to execute the file, i.e. type the path to the script (
./semester) into your shell and press enter.
# Shell Prompt: # zsh: permission denied: ./semester ls -l # We can see semester has no excucute permission
Run the command by explicitly starting the
shinterpreter, and giving it the file
semesteras the first argument, i.e.
sh semester. Why does this work, while
When we run sh interpreter and give
semesteras it’s argument, we actually use the
shprogram to read the
semesterfile’s content and run the
shprogram instead of running
Look up the
chmodprogram (e.g. use
chmodto make it possible to run the command
./semesterrather than having to type
sh semester. How does your shell know that the file is supposed to be interpreted using
chmod +x semester # shebang lines including a path to choose which interpreter to use.
>to write the “last modified” date output by
semesterinto a file called
last-modified.txtin your home directory.
./semester | grep -i "last-modified" > /home/last-modified.txt
Write a command that reads out your laptop battery’s power level or your desktop machine’s CPU temperature from
/sys. Note: if you’re a macOS user, your OS doesn’t have sysfs, so you can skip this exercise.
# Actually I am using macOS, and I run the command in WSL for Win10 on my Desktop. # It works fine. cat /sys/class/power_supply/battery/capacity # And the WSL can't fetch temperature, you can see it in /sys/class/thermal
Publish Date: 2020-03-17
Update Date: 2020-03-18
Word Count: 454
Read Times: 2 Min