I am writing my first bash script and I can't find the solution to my problem.
Lets say I am calling ls -l
and I want to save the names of certain files to a variable.
Output of ls -l
:
-rw-r--r-- 1 user1 user1 125 Apr 19 2021 aaa
drwxrwxr-x 5 user2 user2 4096 Sep 7 15:54 bbbb
drwxr-xr-x 4 user3 user3 4096 Mär 16 2021 cccc
drwxr-xr-x 7 user1 user1 4096 Mai 18 15:32 asdf
To parse the output I use the following command:
`ls -l | while read a b c d e f g h j; do echo $c $j
Which results to:
user1 aaa
user2 bbbb
user3 cccc
user1 asdf
Now the step I cant figure it out is how to filter out based on on the values of j
. Lets say, we have an array values=(aaa cccc)
. How could I extend my command, so that it prints out the users only if the value of j
is a value in the array values
?
Final result should be:
user1 aaa
user3 cccc