Fall 2026
  • Discord
  • Gradescope
  • Syllabus

On this page

  • Question 1
  • Question 2
  • Question 3
  • Question 4
  • Question 5
  • Question 6
  • Question 7
  • Question 8
  • Question 9
  • Question 10
  • Question 11
  • Question 12
  • Question 13
  • Question 14
  • Question 15
  • Question 16
  • Question 17
  • Question 18
  • Question 19
  • Question 20
  • Question 21
  • Question 22
  • Question 23
  • Question 24
  • Question 25
  • Question 26
  • Question 27
  • Question 28
  • Question 29
  • Question 30
  • Question 31
  • Question 32
  • Question 33
  • Question 34
  • Question 35

The Shell: Practice Questions

For each snippet, write the output of its final command. If it prints nothing, write “No Output”.

Each snippet starts in a new, empty directory.

For Git questions, assume git init starts on main and commits succeed.

Question 1

echo 'hello world' >> README
echo 'hola mundo' > README
echo 'salve munde' >> README
cat README | wc -l
Answer
2

Question 2

echo 'hello world' >> README
echo 'hola mundo' >> README
echo 'salve munde' >> README
wc -l README
Answer
3 README

Question 3

echo 'hello world' > README
echo 'hola mundo' >> README
echo 'salve munde' > README
wc -l < README
Answer
1

Question 4

echo 'x = 1' >> example.py
echo 'x += 1' >> example.py
echo 'print("x=", x)' >> example.py
python3 example.py
Answer
x= 2

Question 5

echo 'xs = [1, 2]' >> example.py
echo 'xs.append(5)' >> example.py
echo 'print("xs=", xs)' >> example.py
python3 example.py
Answer
xs= [1, 2, 5]

Question 6

python3 <<EOF
x = 1
x += 1
print("x=", x)
EOF
Answer
x= 2

Question 7

cat > example.py <<EOF
x = 1
x += 1
print("x=", x)
EOF
python3 example.py
Answer
x= 2

Question 8

cat > example.py <<ROFL
x = 1
x += 1
print("x=", x)
ROFL
python3 example.py
Answer
x= 2

Question 9

cat > example.py <<EOF
import sys
print("sys.argv=", sys.argv)
EOF
python3 example.py hello world
Answer
sys.argv= ['example.py', 'hello', 'world']

Question 10

cat > example.py <<EOF
import sys
print("sys.argv=", sys.argv)
EOF
python3 example.py "hello world"
Answer
sys.argv= ['example.py', 'hello world']

Question 11

cat > example.py <<EOF
import sys
print("sys.argv=", sys.argv)
EOF
python3 example.py 'hello world'
Answer
sys.argv= ['example.py', 'hello world']

Question 12

cat > example.py <<EOF
import sys
num_args = len(sys.argv)
print("num_args=", num_args)
EOF
python3 example.py "salve munde" "hola mundo"
Answer
num_args= 3

Question 13

cat > example.py <<EOF
import sys
num_args = len(sys.argv)
print("num_args=", num_args)
EOF
python3 example.py "salve munde' 'hola mundo"
Answer
num_args= 2

Question 14

cat > example.py <<EOF
import sys
num_args = len(sys.argv)
print("num_args=", num_args)
EOF
python3 example.py
Answer
num_args= 1

Question 15

touch hello_world
touch hola_mundo
touch salve_munde
ls | wc -l
Answer
3

Question 16

touch 'hello world'
touch "hola mundo"
touch salve munde
ls | wc -l
Answer
4

Question 17

touch 'hello world' hola "mundo salve munde"
ls | wc -l
Answer
3

Question 18

export password="hello world"
cat > quiz.py <<'EOF'
import os
print(os.getenv('password', 'hola mundo'))
EOF
python3 quiz.py
Answer
hello world

Question 19

export password=hello
cat > quiz.py <<'EOF'
import os
print(os.getenv('password', 'hola'))
EOF
python3 quiz.py
Answer
hello

Question 20

export PASSWORD=hello
cat > quiz.py <<'EOF'
import os
print(os.getenv('password', 'hola'))
EOF
python3 quiz.py
Answer
hola

Question 21

touch README
echo 'API_KEY=asd' > .env
ls -1
Answer
README

Question 22

touch README
echo 'API_KEY=asd' > .env
ls -1a
Answer
.
..
.env
README

Question 23

touch README
mkdir test
touch test/README
cd test
echo 'API_KEY=asd' > ../.env
ls -1a
Answer
.
..
README

Question 24

touch README
mkdir test
mkdir test/test
touch test/README
touch test/test/README
cd test/../test
ls | wc -l
Answer
2

Question 25

touch README
mkdir test
cd test
mkdir test
touch README
cd ..
touch README
ls | wc -l
Answer
2

Question 26

touch README
mkdir test
touch test/README
touch test/.env
ls -a test | wc -l
Answer
4

Question 27

touch README
mkdir test
touch test/README
touch test/.env
ls test | wc -l
Answer
1

Question 28

touch README
mkdir test
mkdir test/test
touch test/README
touch test/test/README
cd test/../test
ls . | wc -l
Answer
2

Question 29

touch README
mkdir test
mkdir test/test
touch test/README
touch test/test/README
cd test/../test
ls .. -a | wc -l
Answer
4

Question 30

git init
touch README
mkdir foo
touch foo/README2
touch README3
ls foo | wc -l
Answer
1

Question 31

git init
touch README
mkdir foo
touch foo/README2
touch README3
ls -a foo | wc -l
Answer
3

Question 32

git init
touch README
mkdir foo
touch foo/README2
touch README3
ls -a . | wc -l
Answer
6

Question 33

git init
mkdir master
echo "print('hello world')" > master/foo.py
echo "print('hola mundo')" > foo.py
git add master
git commit -m "added master"
git branch foo
git checkout foo
echo "print('hola mundo')" >> foo.py
git add foo.py
git commit -m "modified foo"
git checkout main
ls -1
Answer
master

Question 34

git init
echo "print('hello world')" > foo.py
echo "print('hola mundo')" > bar.py
git add foo.py
git commit -m "added foo"
git branch foo
git checkout foo
echo "print('hola otra vez')" >> foo.py
git add foo.py
git add bar.py
git commit -m "modified foo"
git checkout main
echo "print('hello again')" >> bar.py
python3 bar.py
Answer
hello again

Question 35

git init
echo "print('hello world')" > foo.py
git add foo.py
git commit -m "added foo"
git branch foo
git checkout foo
echo "print('hola mundo')" >> foo.py
git add foo.py
git commit -m "modified foo"
git checkout main
python3 foo.py
Answer
hello world