We can iterate over each line from standard input by using while and read
commands.
while read -r line; do
# Process each line here
done
Given /etc/passwd file as standard input (&0),
extract the login shell and convert them to uppercase.
script.sh shell script file.&0).&1).root:x:0:0:root:/root:/bin/bash
user:x:1000:1000:User:/home/user:/bin/bash
Sayan:x:1001:1001:Sayan:/home/sayan:/bin/zsh
BASH
BASH
ZSH
/etc/passwd.:).## Motivation We can iterate over each line from standard input by using `while` and `read` commands. ```bash while read -r line; do # Process each line here done ``` ## Problem Statement Given `/etc/passwd` file as standard input (`&0`), extract the login shell and convert them to uppercase. ## Instructions - Write your solution in `script.sh` shell script file. - The script should read the input from standard input (`&0`). - The output should be printed to standard output (`&1`). - No files will be provided, so you need to read from standard input. ## Sample Input ```text root:x:0:0:root:/root:/bin/bash user:x:1000:1000:User:/home/user:/bin/bash Sayan:x:1001:1001:Sayan:/home/sayan:/bin/zsh ``` ## Sample Output ```text BASH BASH ZSH ``` ## Constraints - The input will always be in the format of `/etc/passwd`. - Login shells are the last field in each line, separated by a colon (`:`). ## Hints - Try using variable manipulation solely to solve this question. ## Motivation ### Folding A line of text can be folded into multiple lines in two broad ways: - **Fixed-width folding**: where each line has a fixed number of characters. This can be done using the `fold` command in Linux. - **Variable-width folding**: where the line is folded based on the content, such as breaking at spaces or punctuation. This can be done using the `grep -o` command in Linux. ```bash > cat data 123456789 > fold -w 3 data 123 456 789 ``` ```bash > grep -o '[0-9]\+' <<< "1,23,456" 1 23 456 ``` ### Unfolding Unfolding is the reverse of folding, where multiple lines are combined into a single line. This can be done using the `paste` command in Linux. ```bash > cat data 1 2 3 > paste -sd+ < data 1+2+3 ``` Read more about them in `man fold`, `man grep`, and `man paste`. ## Problem Statement You are given a line of vector arithmetic expression in the form of `[a1,a2,...,an]+[b1,b2,...,bn]`, where `ai` and `bi` are integers. Your task is to compute the result of the vector addition and return it in the same format. ## Instructions - Write your solution in `script.sh` shell script file. - The script should read the input from standard input (`&0`). - The output should be printed to standard output (`&1`). - You can use temporary files in your current directory if required. ## Sample Input ```text [1,2,3]+[2,6,2] ``` ## Sample Output ```text [3,8,5] ``` ## Constraints - To keep the question simple, the expressions will always be of a sum of two vectors. - The expressions will always be well-formed. - The number of elements in the vectors will be the same. ## Motivation ### Fibonacci Numbers Fibonacci numbers are a sequence of numbers where each number is the sum of the two preceding ones, usually starting with 1 and 1. The sequence commonly starts as follows: 1, 1, 2, 3, 5, 8, 13, 21, and so on. $$ F_n = F_{n-1} + F_{n-2} $$ ## Problem Statement You are given a positive integer `n`. Your task is to print a right triangle of `n` rows consisting of the first $n \times (n + 1) / 2$ fibonacci numbers. ## Instructions - Write your solution in `script.sh` shell script file. - The script should read the integer `n` from standard input. - The output should be formatted as a triangle, with each row containing the appropriate number of fibonacci numbers. ## Sample Input ```text 5 ``` ## Sample Output ```text 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 ``` ## Constraints - `n` is a positive integer. - The padding for each row is using tabs to align the triangle. - The output should be formatted with each number separated by a tab.