105.1 Customize and use the shell environment — Lesson 1

Livestream date: 2026-05-10

Weight 4

Key knowledge areas

  • Set environment variables (e.g. PATH) at login or when spawning a new shell.
  • Write Bash functions for frequently used sequences of commands.
  • Maintain skeleton directories for new user accounts.
  • Set command search path with the proper directory.

Homework 0:

Read the entire exercise with understanding, from the PDF or by re-watching the VOD embeded above.

Homework 1:

In Bash we can write a simple Hello world! function by including the following code in an empty file:

function hello() {

    echo "Hello world!"

}
  1. What should we do next to make the function available to the shell?
  2. Once it is available to the current shell, how would you invoke it?
  3. To automate things, in what file would you put the function and its invocation so that it gets executed when user2 opens a terminal from an X Window session? What type of shell is it?
  4. In what file would you put the function and its invocation so that it is run when root launches a new interactive shell irrespective of whether it is login or not?

(you can click reply to this post)

Homework 2:

Have a look at the following basic, Hello world! bash script:

#!/bin/bash

#hello_world: a simple bash script to discuss interaction in scripts.

echo "Hello world!"
  1. Suppose we make the script executable and run it. Would that be an interactive script? Why?
  2. What makes a script interactive?

Homework 3:

Imagine you have changed the values of some variables in ~/.bashrc and want those changes to take effect without a reboot. From your home directory, how could you achieve that in two different ways?

Homework 4:

John has just started an X Window session on a Linux server. He opens a terminal emulator to carry out some administrative tasks but, surprisingly, the session freezes and he needs to open a text shell.

  1. How can he open that tty shell?
  2. What startup files will get sourced?

Homework 5:

Linda is a user of a Linux server. She kindly asks the administrator to have a ~/.bash_login file so she can have the time and date printed on the screen when she logs in. Other users like the idea and follow suit. The administrator has a hard time creating the file for all other users on the server so he decides to add a new policy and have ~/.bash_login created for all potential new users. How can the administrator accomplish that task?

Extra homework:

  1. What is set -x used for?
  2. What is going to happen when you press ALT + . in Bash?
  3. What are !! and !$ used for, in Bash?
  4. What is the command . ~/.bashrc going to do?
  5. What is skel directory used for?
  6. What is command echo $0 going to tell us?
  7. What is CTRL + ALT + F2?
  8. What is Sakura?
  9. Are GNU tools using one or two dashes before the parameter passed to the command?
  10. What is sudo -iu doing?
  11. Read through login and non-login shell differences once again.

The above are some of the notes that I have noticed, during the live stream, that were not entirely clear to active students in chat. Please find answers to all of them.

Homework 1

  1. i asume make it executable with chmod +x then coppy it to bin/bash so bash can find it
  2. to invoke it we would then type bash helloworldfilename
  3. if we put function inside home/user2/.profile so wen user2 enters terminal it runs and shows the text automatically and we would be in a -bash shell
  4. you would put the function inside home/.bashrc for login and etc/bash/.bachrc for non-login

Homework 2

  1. this scrip is not interactable becuse it just runs there is no wait for user input or other sutch things
  2. if script had user input like arguments it would be interactive

Homework 3

dont know or even undersand Homework 3

Homework 4

  1. John would press ctrl+alt+f1 for a tty consoll
  2. home/.bashrc and bash/.bashrc

Homework 5

  1. you would alter the SKEL in /etc/adduser.conf

Extra homework

  1. set -x prints every command to consol with stdin and stdout for easy debuging to see what the command or script did
  2. same as up arrow but diffirent?!
  3. !! = same command as befor but you can put sudo or other comands with it !$ = stdout of previus command
  4. its gona run bashrc so basically start a teminal
  5. SKEL directory store templets of .bashrc and .bash_login etc for easy coppying
  6. 0$ will show what terminal we use like bash
  7. well run terminal on slot ps2
  8. Sakura is a terminal emulator with the name of a japanise cherryblosom tree
  9. GNU tools use 2 dashes
  10. sudo -iu will say missing parameter sens it want to -l login to -u user thats missing
  11. no
1 Like

H1/1 - executable sounds about right, but copying a script to “bin/bash” doesn’t sound right.
H1/2 - you CAN run the script like that, but if you run it like that it doesn’t have to be executable. scripts that are executable - you can simply execute them with ./script.sh
H1/3 - unfortunately no. only ~/.bashrc will execute in this scenario
H1/4 - I’d say it’s a trick question and it’s the same with root = ~/.bashrc

H2/1 - I’d say you are very correct/logical on this
H2/2 - this as well.

H3 - you have changed things in ~/.bashrc and you wish to apply the changes ASAP. you need to “source” the ~/.bashrc file with either source command or with the . command

H4/1 - yes
H4/2 - “all four” startup files will get executed: both local and system bashrc and both local and system profile