Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
BashAssignments
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vishal Vaddadhi
BashAssignments
Commits
5168211a
Commit
5168211a
authored
Mar 26, 2021
by
vagrant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated cleaner number 2
parent
bcf93ad3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
20 deletions
+23
-20
questionTwo.sh
question2/questionTwo.sh
+23
-20
No files found.
question2/questionTwo.sh
View file @
5168211a
#!/bin/bash
declare
-a
arrayOne
declare
-a
arrayTwo
#
declare -a arrayOne
#
declare -a arrayTwo
arrayOne
=(
$(
awk
-F
:
'{ print $1 }'
/etc/passwd
)
)
arrayTwo
=(
$(
awk
-F
:
'{ print $6 }'
/etc/passwd
)
)
#
arrayOne=($(awk -F: '{ print $1 }' /etc/passwd))
#
arrayTwo=($(awk -F: '{ print $6 }' /etc/passwd))
for
i
in
"
${
arrayOne
[@]
}
"
do
echo
$i
done
#
for i in "${arrayOne[@]}"
#
do
#
echo $i
#
done
for
val
in
"
${
arrayOne
[@]
}
"
do
if
[
$val
==
$1
]
;
then
echo
"
${
arrayTwo
[
$val
]
}
"
break
else
echo
"User "
\"
"
$1
"
\"
" not found"
break
fi
done
#
for val in "${arrayOne[@]}"
#
do
#
if [ $val == $1 ]; then
#
echo "${arrayTwo[$val]}"
#
break
#
else
#
echo "User "\""$1"\"" not found"
#
break
#
fi
#
done
echo
${
arrayOne
[@]
}
echo
${
arrayOne
[2]
}
#echo ${arrayOne[@]}
#echo ${arrayOne[2]}
user
=
root
grep
"^
$user
"
/etc/passwd |
cut
-d
:
-f1
,6
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment