Hello, I'm writing a bash script, creating users. I want to read a text file with names line by line and perform a function on each. I've tried googling a lot, but nothing is working out for me. I want user to enter the path of file with the names in it one on each line and then I'll add function on it. How can I do this? I'd appreciate a little help on that, Regards
I don't know bash, and i don't know any good bash tutorials on this, nor how to search for that particular search actually. In your case I would use PHP (which can be called in console mode from the commandline, python too i think) to call unix useradd with perhaps a config file param, contents of which created by PHP file_put_contents()
Make sure that the file is executable before running it. File name needs to be absolute or within the same directory. #!/bin/bash # Read filename from stdin echo "Enter file path:" read fileName # Output each line while read line;do echo $line done < $fileName Code (markup): Another way of doing it is passing the filename as a parameter instead of requiring user entry (like: ./script filename).