I am new to Scripting, and I am not sure what is wrong with mine. I have not yet added groupadd or useradd commands to actually add the user yet, but I will once I get this part working. So far I have:
!#/bin/bash
if [$# -ne 0 ]
then
echo "usage: $0 < file'
exit 1
fi
first=cut -f 1 -d ',' user_list
last=cut -f 2 -d ',' user_list
lastl=cut -f 2 -d ',' user_list | head -c 1
usern=$first $lastl | tr 'A-Z' 'a-z'
tname=$first $last
while read line; do
echo "adding $tname : $usern\n"
done < user_text
The output should look like adding Jet Black: jetb
but its kind of all over the place. Any help or hints as to what I'm doing wrong would help a lot.
This is a syntactically correct version of your script:
I think you want to delete the space between
$first
and$lastl
in$usern
, like this:And then there are lots of improvements to do, probably like twalberg said, but I think your best first step is to understand your syntax errors.
You could probably make it a lot simpler by reading up on the role of the
IFS
variable in word splitting, then writing something like this:Some other things in there to research - substring expansion (
${last:0:1}
), character classes fortr
([:upper:]
, etc.), capturing output from commands ($(...)
).