LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-21-2003, 02:30 AM   #1
nzx
LQ Newbie
 
Registered: Oct 2003
Posts: 1

Rep: Reputation: 0
Unhappy my adding user script seems weird and buggy


Hi all,

i'm writing a piece of code to perform the process of adding users script, however i have encountered some problems that i can not solve, can anyone give me some hints on this code.

1. when i read in the names from the file, it will read in all the first name and then read in all the last names, so it will display something like: f1 f2 f3l1 l2 l3 instead of
f1l1
f2l2
f3l3

2. is there a more clever way to convert capital letters into small letters, right now it's working fine, but if i wanted to make it to convert the username into small letters in the ealier stage it does not work, and if i want to put all the data into one line, the line will not be displayed. And the following is my code.


This is my scriptFile
--------------------------------------------------------------------------------
#!/bin/sh

# Test to see if the userDataBaseFile exists and there should only one argument after the scriptFile
# eg: correct format : scriptFile userDataBaseFile

if [ $# = 0 ] || [ $# -ge 2 ] || [ ! -f $1 ]

then
echo Error: Problem with the command line argument

# If there are no errors the program will continue
else

for line in `cat $1`;
do
first=`cat $1 | cut -c1`

last=`cat $1 | cut -f1 -d "," | cut -f2 -d " " | cut -c1-7`

gecos=`cat $1 | cut -f1 -d ","`

username=$first$last

echo "gecos = "$gecos
echo "username = "$username | tr '[:upper:]' '[:lower:]'
echo "home directory = "/home/$username | tr '[:upper:]' '[:lower:]'

done

fi

-------------------------------------------------------------------------------
This is the content in my userDatafile, which is $1

John Smith,100,/bin/bash
Harry Potter,101,/bin/sh
Johnny Wilkinson,102/bin/csh


Edit: moved to the Programming forum

Last edited by mcleodnine; 10-21-2003 at 02:32 AM.
 
Old 10-21-2003, 07:29 AM   #2
nhs
Member
 
Registered: Aug 2003
Location: Edinburgh, Scotland
Distribution: Gentoo
Posts: 246

Rep: Reputation: 30
Change first=`cat $1 | ...` to first=`echo $line |` for the first variable. You will need to make the same changes to the lines setting last and gecos.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script adding autostart gnome script Coolrunr Programming 3 01-01-2009 02:23 PM
I need help with this script - it is weird kal2005 Programming 6 07-07-2005 08:41 AM
Need help with the script - it is weird kal2005 Solaris / OpenSolaris 1 07-05-2005 05:12 PM
Intermediate Linux user looking to settle on non buggy desktop distro thebeast Linux - Distributions 31 10-08-2004 02:55 PM
Adding multiple user shell script plexus Programming 2 06-19-2004 08:36 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration