I am having a lot of difficulties with one of my homework assignments and was wondering if I could get some help on this.
Here are the instructions
1.Sets an alias for the less command so that it will display line numbers when l is used and the filename is passed:
a. Ex: l filename
2.Reads the /etc/passwd file, use the variable Line to store the data
3.Uses a function to process the data read from /etc/passwd
a. Use the global variable, Line, when processing the data
b. Information passed to the function from the main script is:
1)The username field number
2)The UID field number
c. The function will determine which UIDs are less than 100 and then write those to a file named results.hw5.txt in the user’s home directory
i.use the form: user’s ID = UID /// user’s name = username
ii.Ex: user’s ID = 0 /// user’s name = root
d.Any variables created within the function must be local.
4.Uses the alias created in Step 1 to read results.hw5.txt
Here is what I have so far.
#!/bin/bash
function func1
{
local filename=/etc/passwd
local results=~/My_Scripts/results.hw5.txt
while IFS=: $line -p uid _ user _
do
((uid<=100)) && echo "user id = $uid /// username = $user" > $results
done < $filename
}
alias l='less'
line=$(read)
func1
l $results
while read Line; do ...; done < /etc/passwdoutside the function.Linein the loop, then extract the username and UID from this, then callfunc1 $username $uid