Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am new to Linux and I'm enrolled in college course. I need help writing a simple bash script, but I have not had any instruction on scripting. We are suppose to use the "man" pages and write the scripts on our own. Can anyone provide links that better describe how to script. The man pages are more for Linux users, not for us Windows users. The pages read more like greek to me. I need to write a script to add users from a list. The list is in the format of Lastname,Firstname and I need to username to first initial last name (flastname) all lower case. What command do I use and where can I find simpler instructions on how to do this.
Here's somethign I'd like to see. By the time you read this, my assignment will be over with so don't worry about doing my work for me. Can someone that knows what they are doing post a bash script that adds user from a list? The list format will be Firstname, Lastname. The username is going to be the first initial wit the last name, all lowercase. (flastname). I'd just like to see where I was going wrong. Most of the time my script would just hang and do nothing, or it would return invalid username.
Originally posted by vadon Here's somethign I'd like to see. By the time you read this, my assignment will be over with so don't worry about doing my work for me.
Never planned on doing your work for you.. as this is also stated in our RULES. Which will lead to your next question and my followup...
Quote:
Can someone that knows what they are doing post a bash script that adds user from a list? The list format will be Firstname, Lastname. The username is going to be the first initial wit the last name, all lowercase. (flastname). I'd just like to see where I was going wrong. Most of the time my script would just hang and do nothing, or it would return invalid username.
Now why would would post a script up here for you to copy from? That's not an effecient way to learn and do work your suppose to do yourself and you're never going to learn that way.
If you want help, why not post your script you have and we could perhaps tutor you on your mistakes, instead of giving you the answer.. then you'll actually learn something most likely.. but remember our rules you agreed to and that I linked to above.. don't expect anyone to do the work for you..
#!/bin/bash
clear
read TheUSER
while [ "TheUSER" != "" ]
do
read TheUSER
echo The User is $TheUSER
useradd $TheUSER
done
echo "All user names have been added"
my list file was cut down to just a sinlge name for testing.
userlist.txt contains:
Howard
Howard1
Fine
I removed the first names and added a 1 to the second Howard to test the script before I tried using the cut command to:
#!/bin/bash
clear
read TheUSER
while [ "TheUSER" != "" ]
do
read TheUSER | cut -f2-1 (I think this would return the first chacter after the comma) | tr [A-Z] [a-z] (I think this would change all caharters to lowercase)
echo The User is $TheUSER
useradd $TheUSER
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.