私は宿題の1つで多くの問題を抱えています。ここでBash関数スクリプト
は、ここで説明
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
ある私がこれまで持っているものです。 IFS =ながら
#!/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
'Line while read;のようなものが必要です。行う ...; done etc/passwd'を実行してください。 – Barmar
この関数は、ユーザー名とUIDをパラメーターとみなしています。 – Barmar
ループの 'Line'にラインを読み込み、それからユーザ名とUIDを抽出し、' func1 $ username $ uid'を呼び出す必要があります – Barmar