0x03 Shell init files variables and expansions- Task Solved

Описание к видео 0x03 Shell init files variables and expansions- Task Solved

Shell
A shell is a command-line interface that interprets user input and executes commands. The most common shells in Unix-like systems are bash, zsh, and fish. The shell provides a way for users to interact with the operating system, run scripts, and manage system resources.

Init files
An init file is a script that runs when a shell is started. The name and location of the init file depend on the shell being used. For example, in bash, the init file is called .bashrc and is located in the user's home directory. In zsh, the init file is called .zshrc. The init file can be used to set environment variables, aliases, and customize the shell's behavior.

Variables
Variables in the shell are used to store values that can be used by the shell or by scripts. Shell variables can be set with the = operator, and they are case-sensitive by default. Some common shell variables include:

$HOME: the user's home directory
$PATH: a colon-separated list of directories where the shell looks for executable files
$USER: the username of the current user
$PWD: the current working directory
Expansions
Expansions are a way to manipulate shell variables or other data in the shell. The most common expansions are:

Parameter expansion: this allows you to manipulate the value of a shell variable by adding prefixes or suffixes to it, or by substituting parts of the variable with other text.
Command substitution: this allows you to run a command and use its output as a variable or argument in another command.
Arithmetic expansion: this allows you to perform arithmetic operations in the shell using variables or literal values.
Brace expansion: this allows you to generate a list of strings based on a pattern, which can be used as arguments in a command. For example, {a,b,c} would expand to a b c.

Task 11 : 11-binary_to_decimal Explanation
This is a Bash script that performs a binary-to-decimal conversion and prints the result to the console.


The script uses the $BINARY variable, which is assumed to contain a binary number represented as a string of 0s and 1s. The syntax $((expression)) is used to evaluate arithmetic expressions in Bash.


The expression 2#$BINARY performs a binary-to-decimal conversion by interpreting the value of $BINARY as a base-2 (binary) number. The 2# prefix tells Bash to interpret the following string as a base-2 number. Therefore, when this script is executed, it will convert the binary value stored in $BINARY to decimal and print the result to the console.


Note that if the $BINARY variable does not contain a valid binary number, an error will occur when this script is executed.

Task 12 : 12-combinations
This is a Bash script that generates a list of all two-letter combinations of lowercase letters from a to z, prints each combination on a separate line, and filters out any lines that contain the string "oo".


Let's break it down step by step:


{a..z}{a..z}: This generates all two-letter combinations of lowercase letters from a to z.
echo {a..z}{a..z}: This prints the list of two-letter combinations to the console, separated by spaces.
tr " " "\n": This replaces all spaces in the output with newlines, so that each combination is printed on a separate line.
grep -v "oo": This filters out any lines that contain the string "oo". The -v option tells grep to invert its output, so that only lines that do not match the pattern are printed.
Therefore, when this script is executed, it will print all two-letter combinations of lowercase letters from a to z, one per line, except for any combinations that contain the string "oo".

Email:[email protected]
Content Review Video:    • 0x03 Shell init files variables and e...  

Комментарии

Информация по комментариям в разработке