22 Questions
What do the numbers 666 and 644 represent in a file permission mode?
The file permission modes for users, groups, and others
What is the main difference between the file permission modes 666 and 644?
Others may write a file in 666 but not in 644
What is a shell variable?
An area of memory that can store information, referred to by a name
What is the purpose of the 'printenv' command?
To print the values of all environment variables
What is an environment variable?
A dynamic object that stores a value, referenced by one or more programs
What is one of the uses of environment variables?
To determine the directory to install files in
What is the difference between a shell variable and an environment variable?
Shell variables are used by the shell, while environment variables are used by programs
What is an advantage of using environment variables?
They can be referenced by one or more programs
What is the purpose of the HOME environment variable?
To show the current user's home directory
What does the PWD environment variable store?
The value of your current working directory
What is the purpose of the echo command?
To write arguments to the standard output
What is the purpose of using the $
symbol with a variable in the echo command?
To print the value of the variable
What is the purpose of using backticks or the $()
syntax in the echo command?
To ask the shell to substitute the results of a given command
What is a shell script?
A file containing a series of commands
What is the purpose of the PATH environment variable?
To contain a colon-separated list of directories that the system searches to find the executable program corresponding to a command
What is the purpose of using the –e
option with the echo command?
To jump to another line
What is the purpose of the shebang line in a script?
To specify the interpreter to be used to execute the script
What is the effect of using chmod u+x
on a script file?
It adds execute permissions to the owner of the file
What is the benefit of using variables in shell scripts?
It makes the script easier to maintain and reduces the amount of typing
What is the purpose of the which
command in shell scripts?
To locate the executable file associated with a given command
What is the effect of using chmod 744
on a script file?
It sets the file permission modes to read, write, and execute for the owner, and read-only for the group and others
What is an example of an absolute path to an interpreter in a script?
#!/usr/bin/perl
Study Notes
Environment Variables
- Environment variables help shape the environment where the commands are executed.
- Examples of environment variables: HOME (current user's home directory), PATH (directories where the system searches for executable programs), PWD (current working directory).
Shell Scripting
- Shell scripts are short programs written in a shell programming language to automate tasks under Linux OS.
- A shell script is a file containing a series of commands.
- Shell scripts are useful for performing the same actions on many different files.
- Echo command is commonly used in shell scripts to display messages or instructions.
Echo Command
- Syntax: echo options arguments
- Writes arguments to the standard output.
- Can be used to print results or ask the user for input.
- Examples:
-
echo "Bioinformatics is great \n starting writing scripts"
-
echo –e “Bioinformatics is great \n starting writing scripts”
-
X=firstvariable; echo X; echo $X
-
Running Commands and Substitution
- Print the result of a command using backticks `` or $( ) parentheses.
- Examples:
-
echo
pwd`` -
echo $(pwd)
-
Shell Scripts
- A shell script is a file containing a series of commands.
- Shell script = scripting interpreter + command-line interface to the system.
- Shell scripts can be used to automate tasks and display messages or instructions.
Creating a Shell Script
- Steps to create a shell script:
- Create a new file using a text editor (e.g.,
nano myfirstscript
). - Write the script content (e.g.,
#!/bin/bash; echo "Hey, I am starting writing shell scripts"
). - Run the script using
./
(e.g.,./myfirstscript
). - Change the file permissions to make it executable (e.g.,
chmod u+x myfirstscript
orchmod 744 myfirstscript
).
- Create a new file using a text editor (e.g.,
Shebang
-
#!
is called the shebang, which indicates the beginning of a script. - The shebang is followed by the absolute path to an interpreter executable (e.g.,
/bin/bash
or/usr/bin/perl
). - The
which
command can be used to locate the executable file associated with a given command.
Learn about environment variables in the context of bioinformatics, including examples like HOME and PATH, and their role in shaping the environment for online courses like IBT.
Make Your Own Quizzes and Flashcards
Convert your notes into interactive study material.
Get started for free