LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 02-07-2018, 07:48 AM   #1
galvantua
LQ Newbie
 
Registered: Feb 2018
Posts: 3

Rep: Reputation: Disabled
Getting a parse error in bash script


I am making a bash script that needs to config som files, and while testing it, I came across what shellcheck.net called a parser error in the following line:

Code:
#!/bin/bash
while true; do
read -p "Do you wish to config Open-SSH Server?: " yn 
case $yn in
[Yy]* ) echo "Starting ssh config";
open my $in,	'<', /etc/ssh/sshd_config	or die "Can't read old file: $!"; 
open my $out,	'>', /etc/ssh/sshd_config	or die "Can't write new file: $!"; 

while ( <$in> ) {
#sets functions for ssh values to reduce code(lines 12-45)
function good_value {
	if [ $valuename = PermitRootLogin ]||[ $valuename = PermitEmptyPasswords ]||[ $valuename = DebianBanner ]||[ $valuename = PasswordAuthentication ]
	then 
#...
The line in question is line 9: while ( <$in> ) {
I have a bracket at the end as well. how do i fix this parser error?
 
Old 02-07-2018, 07:48 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,781

Rep: Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935
Welcome to LinuxQuestions.

Code:
open my $in,	'<', /etc/ssh/sshd_config	or die "Can't read old file: $!"; 
open my $out,	'>', /etc/ssh/sshd_config	or die "Can't write new file: $!";
Looks like your trying to convert perl to bash. In addition, that
Code:
while ( <$in> ) 

in perl is something like

while ( my $valuename = <$in> )
However, none of the above statements will work in bash (as far as I know...) A simple loop to read a file
Code:
file="myfile"
while  read line
do
        # display $line or do somthing with $line
	echo "$line"
done <"$file"
 
1 members found this post helpful.
Old 02-07-2018, 08:14 PM   #3
galvantua
LQ Newbie
 
Registered: Feb 2018
Posts: 3

Original Poster
Rep: Reputation: Disabled
Talking Ohh...

oh ok. i didn't realize that bash didn't get perl syntax too. does this mean i will have to change these 2 lines?
Code:
#!/bin/bash
perl -i -pe 's/PASS_MAX_DAYS	99999/PASS_MAX_DAYS	90/g' /etc/login.defs
perl -i -pe 's/PASS_MIN_DAYS	0/PASS_MAX_DAYS	10/g' /etc/login.defs
 
Old 02-07-2018, 08:28 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,781

Rep: Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935
No, they should work as is because they are both command line statements.

Last edited by michaelk; 02-07-2018 at 08:30 PM.
 
1 members found this post helpful.
Old 02-07-2018, 08:30 PM   #5
galvantua
LQ Newbie
 
Registered: Feb 2018
Posts: 3

Original Poster
Rep: Reputation: Disabled
oh ok. thanks for your help, it is most appreciated!
 
  


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] Bash script to parse Output pradeepspa Linux - Newbie 2 01-27-2017 02:44 PM
Parse String in a Bash script jimwelc Linux - Newbie 8 11-09-2012 07:47 AM
How to parse strings in bash script crimson08 Linux - Newbie 17 05-11-2009 11:29 AM
Parse XML in bash script MikeyCarter Linux - Software 1 02-16-2007 01:19 PM
bash script help to parse out text slack guy Linux - Newbie 3 12-30-2004 08:42 AM

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

All times are GMT -5. The time now is 11:30 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