Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What two files in your home directory are read by your shell when you login? Giv

ID: 3725715 • Letter: W

Question

What two files in your home directory are read by your shell when you login?

Give the command to set a shell variable named NewPath to the current value of the path variable.

List in order the places that a shell checks for the code to execute a user's command.

Explain how to make a shell script into a standalone executable.

Explain the effect of putting the following lines in your .tcshrc file:

Explain the underlying mechanism that causes a command such as

to send the output from ls to the input of grep.

Explain the difference between placing a string in single and double quotes in a command.

Explanation / Answer

1. What two files in your home directory are read by your shell when you login?

Considering bash as the current shell, the following files are read from the home directory.
~/.bash_profile
~/.bashrc

If the shell is zsh, then:
~/.zshenv
~/.zshprofile
~/.zshrc

2. Give the command to set a shell variable named NewPath to the current value of the path variable.

One may place the following line in the ~/.bash_profile or ~/.bashrc:

export NewPath=$PATH

3. List in order the places that a shell checks for the code to execute a user's command.

It's goes on checking according to the paths present in the $PATH environment variable.

Usually, it's:
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

It'll vary as per the system as the users do have their custom paths appended to the $PATH environement variable.

4. Explain how to make a shell script into a standalone executable.

Considering it's a bash script, the following line (called "shebang") must be added on the top (first line) of the script.
#!/bin/bash

Consider a script named myscript.sh located at /home/$USER/myscript.sh, we can make it executable using:
chmod +x myscript.sh

export PATH=$PATH:/home/$USER/

Now, it'll work without needing ./myscript.sh or bash myscript.sh

One can directly envoke it using: myscript.sh (rename it as convenient).

5. Explain the effect of putting the following lines in your .tcshrc file:
alias vi vim
alias pico vi

.tcshrc file is the config file for tcsh shell and it'll run those commands every time the tcsh is run.
The `alias vi vim` will map vi command to vim. Means if you run `vi` command in the tcsh, then it will open vim instead.

Similarly, pico is mapped to vi.

So,
vi -> vim
pico -> vi

So we can say,
pico -> vim

Hence, running command vi or pico will execute vim command.

6. Explain the underlying mechanism that causes a command such as
ls -la | grep System
to send the output from ls to the input of grep.

The underlying mechanism to send output of one command to another as input is called Piping. You can connect two or more than two commands at a time. It's represented by a pipe symbol (|) i.e. a vertical bar. Redirection is allowed but the data only flows in one direction in pipes. Means you can't send the value of "grep System" to "ls -la" as input, talking about the example in the question. For that the input redirection (<)can be used. For example: ls -la < grep System

7. Explain the difference between placing a string in single and double quotes in a command.

If we use the string simply for enclosing some text, then it doesn't really matter.

For example:

$ ls 'helloworld.txt'

or

$ ls "helloworld.txt"

will give the similar results.

Same is the case for mkdir.

$ mkdir 'someDirectory'
and
$ mkdir "someDirectory"

is same.

But the difference comes into play when we use the variables.

For example:

Suppose we define a variable named hi as 5.

$ hi=5

We can simply print it as:
$ echo $hi
5

And if we try to print it by enclosing it by single quote,
$ echo '$hi'
$hi

It just prints it as normal string.

But, if we enclose the variable within double quotes,
$ echo "$hi"
5

Then it expands the variable first before executing the echo command.

This phenomenon is called Shell Variable Expansion.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote