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
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
05-23-2018, 09:28 PM
#1
LQ Newbie
Registered: May 2018
Posts: 4
Rep:
Problem Bash not running.Help Please.
Hello everybody,
Im trying to get this script working but what I get is:
14: Syntax error: "(" unexpected (expecting "fi").
Hope you guys can solve my problem...
Thanks in advance.
Here is the script:
Code:
#!/bin/bash
#========================================
#Eb
#Date: 15/5/2018
#Nombre:ID:Telefono:Direccion:DOB:Departamento:Salario
#
#=========================================
filein="proyecto3.csv"
IFS=$'\n'
if [ ! -f "$filein" ]
then
echo "Cannot find file $filein"
else
groups=(`cut -d: -f 6 "$filein" | sed 's/ //'`)
fullnames=(`cut -d: -f 1 "$filein"`)
userid=(`cut -d: -f 2 "$filein"`)
usernames=(`cut -d: -f 1 "$filein" | tr [A-Z] [a-z] | awk '{print substr($1,1,1) $2}'`)
fi
for group in ${groups[*]}
do
grep -q "^$group" /etc/group ; let x=$?
if [ $x -eq 1 ]
then
groupadd "$group"
fi
done
x=0
created=0
for user in ${usernames[*]}
do
useradd -n -c ${fullnames[$x]} -g "${groups[$x]}" $user 2> /dev/null
if [ $? -eq 0 ]
then
let created=$created+1
fi
echo "${usernames[$x]}" | passwd --stdin "$user" > /dev/null
echo "Complete. $created accounts have been created."
fi
05-23-2018, 11:13 PM
#2
Senior Member
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,860
You have to use
bash to execute this script, not something else like
ksh ,
dash ,
ash .
Code:
$ bash proyecto3.sh
proyecto3.sh: line 24: groupadd: command not found
proyecto3.sh: line 38: syntax error near unexpected token `fi'
proyecto3.sh: line 38: `fi'
$ dash proyecto3.sh
proyecto3.sh: 14: proyecto3.sh: Syntax error: "(" unexpected (expecting "fi")
Last edited by NevemTeve; 05-23-2018 at 11:16 PM .
05-23-2018, 11:31 PM
#3
LQ Newbie
Registered: May 2018
Posts: 4
Original Poster
Rep:
Quote:
Originally Posted by
NevemTeve
You have to use
bash to execute this script, not something else like
ksh ,
dash ,
ash .
Code:
$ bash proyecto3.sh
proyecto3.sh: line 24: groupadd: command not found
proyecto3.sh: line 38: syntax error near unexpected token `fi'
proyecto3.sh: line 38: `fi'
$ dash proyecto3.sh
proyecto3.sh: 14: proyecto3.sh: Syntax error: "(" unexpected (expecting "fi")
Thanks
I tried using bash...what's up with line 38?
Last edited by 13BUBUS; 05-23-2018 at 11:42 PM .
05-23-2018, 11:39 PM
#4
LQ Guru
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Count your "if"s. Now count your "fi"s.
05-23-2018, 11:42 PM
#5
Senior Member
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,860
> I'm using bash...
Cool. Now qoute the output of this command:
Code:
bash yourscriptname
05-23-2018, 11:43 PM
#6
LQ Veteran
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727
use
at the top of the script (after the #! line) to get more information.
Also...don't there need to be spaces around the = in assignments? (lines 14 thru 17)
Last edited by scasey; 05-23-2018 at 11:48 PM .
05-23-2018, 11:45 PM
#7
LQ Veteran
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727
Quote:
Originally Posted by
hydrurga
Count your "if"s. Now count your "fi"s.
Aha...good catch!
05-24-2018, 12:12 AM
#8
LQ Newbie
Registered: May 2018
Posts: 4
Original Poster
Rep:
Quote:
Originally Posted by
hydrurga
Count your "if"s. Now count your "fi"s.
Thank.
Yep, I did the correction. I deleted the last fi but now I still get an error: unexpected end of file.
05-24-2018, 12:16 AM
#9
LQ Guru
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Count your "do"s. Now count your "done"s.
05-24-2018, 12:33 AM
#10
LQ Newbie
Registered: May 2018
Posts: 4
Original Poster
Rep:
Quote:
Originally Posted by
hydrurga
Count your "do"s. Now count your "done"s.
I still get an error...
Unrecognized option '--stdin'.
Very helpful,thank you.
05-24-2018, 12:45 AM
#11
LQ Guru
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
To be entirely frank, 13BUBUS, if you're going to write code then you need to start to learn how to think and also do your own internet searches.
Is this your own code? Genuine question.
passwd --help will show you which command line options your version of passwd supports.
An internet search for "passwd --stdin" returns the following page (read the comments carefully):
https://stackoverflow.com/questions/...-shell-script#
Last edited by hydrurga; 05-24-2018 at 12:48 AM .
1 members found this post helpful.
All times are GMT -5. The time now is 02:44 PM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News