On Sun, Jan 14, 2018 at 03:46:06PM +0300, Gokan Atmaca wrote: > I have the user list and the password list. I shot them with BASH. I > want to give passwords to the usernames in these separate files in > order. > > File names: > Users.list > Passwords.list > > In a loop, I have to not throw them into users of these passwords.
We need to know the contents of these files, not their names. > I did this for it, but it did not work. > > #!bin/bash > passwords = $ (cat passwords.list) > for i in $ (cat passwordlist); do my program $ i $passwords; done There are many mistakes here, even without knowing what the files contain or what you are trying to do with them. First, your shebang is wrong. It must be #!/bin/bash rather than #!bin/bash. Second, your assignment is wrong. It must be var=value rather than var = value. You CANNOT have spaces around the = sign. Third, your command substitution is wrong. It must be $(command) rather than $ (command). You CANNOT have a space between the $ and (. Fourth, if your passwords.list file contains spaces (which many good passwords WILL contain), your entire algorithm is wrong. Your use of $(cat ...) splits the contents of the file on ALL whitespace, not just newlines. A password with a single space in it will be treated as two words, and the loop will iterate once for each of those words. Also (let's call this bug number 4.5), any globbing characters in the password.list file (like ? or * or [...]) will break things with the algorithm you've chosen. And then there's your for loop ... ugh. No. It's just unbearable. This isn't valid code. It's just random characters. > How do I make an Array? Or how can I solve it? Start from the beginning: WHAT IS IN EACH FILE? Suppose users.list looks like this: fred barney wilma betty And suppose passwords.list looks like this: 2^7djfnc5 yabba dabba doo U(n jv7s^& password Now suppose we are told "each line in users.list is one user, and each line in passwords.list is one password". Suppose we are told "there must be the same number of lines in both files". Suppose we are told "line N of users.list corresponds to line N of passwords.list". THEN you have enough information to actually write a program. What kind of array do you want? Why do you even want an array? What is your program supposed to do with these users and passwords? Do you just need to create a single output file which combines them together? In that case, you can read a line at a time from each file and never store them all in an array. Just process sequentially. Do you need to create a lookup table that you will refer to again and again during some sort of GUI? In that case, sure, an array might make sense. But you still need to define what you're doing. Are you planning to look up the password of a user GIVEN the user's name? Then use an associative array which is indexed by the user's name and contains the passwords. Do you plan to look up the user's name and password GIVEN an index number of some kind, perhaps chosen from a menu? Then use two indexed arrays, one that maps the index number to the username, and the other that maps the index number to the password. Until we know what the input files contain, and what your program is supposed to do with them, nobody can tell you how to write your program. Start with these pages: http://mywiki.wooledge.org/BashGuide http://mywiki.wooledge.org/BashPitfalls http://mywiki.wooledge.org/BashFAQ/001 Then, later, when you're ready: http://mywiki.wooledge.org/BashProgramming