LinuxQuestions.org
Help answer threads with 0 replies.
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 05-23-2018, 09:28 PM   #1
13BUBUS
LQ Newbie
 
Registered: May 2018
Posts: 4

Rep: Reputation: Disabled
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
 
Old 05-23-2018, 11:13 PM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,860
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
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.
 
Old 05-23-2018, 11:31 PM   #3
13BUBUS
LQ Newbie
 
Registered: May 2018
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by NevemTeve View Post
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.
 
Old 05-23-2018, 11:39 PM   #4
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
Count your "if"s. Now count your "fi"s.
 
Old 05-23-2018, 11:42 PM   #5
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,860
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
> I'm using bash...

Cool. Now qoute the output of this command:
Code:
bash yourscriptname
 
Old 05-23-2018, 11:43 PM   #6
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
use
Code:
set -xv
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.
 
Old 05-23-2018, 11:45 PM   #7
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Quote:
Originally Posted by hydrurga View Post
Count your "if"s. Now count your "fi"s.
Aha...good catch!
 
Old 05-24-2018, 12:12 AM   #8
13BUBUS
LQ Newbie
 
Registered: May 2018
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by hydrurga View Post
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.
 
Old 05-24-2018, 12:16 AM   #9
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
Count your "do"s. Now count your "done"s.
 
Old 05-24-2018, 12:33 AM   #10
13BUBUS
LQ Newbie
 
Registered: May 2018
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by hydrurga View Post
Count your "do"s. Now count your "done"s.

I still get an error...
Unrecognized option '--stdin'.

Very helpful,thank you.
 
Old 05-24-2018, 12:45 AM   #11
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
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.
  


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
[SOLVED] Problem with running Bash Script C4rtm4N Linux - Newbie 5 02-18-2015 06:30 PM
Problem with running bash script on open terminal window! gnome1919 Linux - Software 2 07-15-2014 07:02 AM
[SOLVED] Problem running Linux bash commands in JAVA using Runtime wizard119 Linux - Newbie 2 03-01-2011 01:23 AM
[SOLVED] Problem Running Bash Script in new Screen.. timdvtemp Programming 4 02-17-2011 07:41 AM
problem in running bash in cgi csdhiman Linux - Server 1 10-09-2007 04:44 PM

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

All times are GMT -5. The time now is 02:44 PM.

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