Pass contents from .txt file as argument to bash script?

I need to "write a script to add users to your system in which user names are assigned to the script as an argument n (in ?, spell error by Professor) format text file

Last_Name  First_Name  Middle_Initial  Group

(other FYI instructions). The script should create unique user names up to 8 characters long and generate random passwords for users. Users should be assigned home directories depending on the group in which they are located. You can assume that users will belong to Management ("mgmt"), "Employee" ("empl"), or "Temporary" ("temp"), and that their respective directories are under these group names in / home. For example, if John Doe is in "mgmt." And his username is jdoe1234, then his home directory should be in / Home / Ctrl / jdoe1234. Lock home directories so that no one has permissions for home directories than the users themselves. Your script should generate a file called users.txt,which contains the following columns:

Surname Name Password UID

which can be used to distribute usernames and passwords to users.

The first part (not in italics) is what confuses me. If I understand his wording correctly, he wants me to take the text from a separate file .txtand use it as arguments for my script? With an idea

./file.sh arg1 arg2 arg3 arg4

besides these arguments will be the first four words in the txt file? Say if the .txt file contains "Doe John A empl" then it will be like input

./file.sh arg1 arg2 arg3 arg4

Here is my attempt so far (I really tried other things, but this is what I have on the screen right now, sort of where I started):

#!/bin/bash
echo "$(cat file.txt)"
lname=$(echo $1|head -c 3)//to make username use first 3 letters of last name
fname=$(echo $2|head -c 1)//to make username use first letter of first name
mname=$3
group=$4
echo "$lname$fname$mname$group"

, . , , , .txt , . , . , . ? , , script, , , , , .txt.

+4
2

$(command) . $(cat some_file), . :

cmd1 $(cat args_file)

, echo $(cat file.txt), , cat file.txt, cat echo, .

$n , n script ($0 script). , . $2, $3 $4 .

, $names=$(cat $1). , cut:

lname=$(cut -d \  -f 1 $1)
fname=$(cut -d \  -f 2 $1)
mname=$(cut -d \  -f 3 $1)
group=$(cut -d \  -f 4 $1)

:

# NOT //.

head , head -c . .

+6

, :

-:. / shell script.

, :

./YourScriptFile.sh $(cat YourInputFile.txt)

-:. .

script:

$1, $3, $4, ..., $n

:

1st, 2nd, 3rd, ..., nth

( ).

:. , 3 , , .

, . :

FirstTwoChars_of_FirstToken=${1:0:2}
FirstTwoChars_of_SeventhToken=${7:0:2}

LastTwoChars_of_FirstToken=${1:7:9} 
# if the first token is "FirstName" it would return you "me"

, .

: : (# )

#!/bin/bash
lname=$(1:0:3) #to make username use first 3 letters of last name
fname=$(2:0:1) #to make username use first letter of first name
mname=$3
group=$4
echo "$lname$fname$mname$group"

script, .

+1

All Articles