Bash scripting Flashcards
What are the layers of an OS?
The Outer “Shell”
Shell - Commands - apps - scripts
Network service - libraries - file systems - frameworks
Sys.calls - device drivers
Kernel
What is a shell?
The outer layerof an OS, where users interact through a graphics-based or text based interface
What is bash?
A command line shell
A program that executes commands on the user’s behalf
What user has UID 0?
Root (superuser)
What does # and $ mean in shell?
When the shell displays a $, it means it is waiting for the user to pass a command.
means the user that is running the shell, is the root user (superuser with administrative rights)
What is the “date” command?
Displays the current date
What is the “pwd” command?
Print working directory
What is the “ls” and “ls -l” commands
list, and long listing
Prints content of working directory
What is the “echo” command?
Prints a string or value of a variable to stdout
What is the first line of a bash script?
!/bin/bash
Shebang: Acombination of bash (#) and bang (!), followed by the bash shell path
What does shebang do?
Tells the shell to execute the script via bash shell
What is shebang?
An absolute path to the bash interpreter
What command can be used to find the bash shell path?
which bash
What is the difference between !¤$ and $_ in the following commands:
mkdir folder && cd !$
mkdir folder && cd $_
!$ gives the last argument of the previous command in the shell history, in this case, the command that was passed to the shell before the mkdir command.
$_ gives the last argument of the previous command, in this case, the argument of mkdir
What does the comman “read var_name” do?
Reads input and stores the input value in the following variable, in this case var_name
How are variables assigned in bash?
- Assign value directly: country=Norway
- Command substitution:
same_country=$country