LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-21-2015, 12:00 AM   #1
networkguy
LQ Newbie
 
Registered: Sep 2015
Posts: 4

Rep: Reputation: Disabled
simple shell script EOF error


Hi

I am new to shell scripting so I might be missing something obvious

Could you please help me understand what I am missing in following script?

I don't think I am missing any quotes

./ab1
How many counters to inspect?
^C
root@abcd:~# bash -nv ab1
#!/bin/bash
echo "How many counters to inspect?"
read NO_CNTRS_TO_INSPECT
i=1
while [ $i -le $NO_CNTRS_TO_INSPECT ]
do
echo "Which Counter to inspect?"
read CNTR_TO_INSPECT$i
#echo CNTR_TO_INSPECT$i
((i++))
done
echo "Which showtech do you want to inspect?"
read SHOWTECH_TO_INSPECT
#egrep -i "== clock|$CNTR_TO_INSPECT" $SHOWTECH_TO_INSPECT



if [ $NO_CNTRS_TO_INSPECT==1 ]
then
egrep -i "== clock|$2|$SHOWTECH_TO_INSPECT

else
if [ $NO_CNTRS_TO_INSPECT==2 ]
then
egrep -i "== clock|$2|$3|$SHOWTECH_TO_INSPECT"
else
echo "max 2"
fi
fi

ab1: line 27: unexpected EOF while looking for matching `"'
ab1: line 31: syntax error: unexpected end of file
 
Old 09-21-2015, 12:56 AM   #2
kaushalpatel1982
Member
 
Registered: Aug 2007
Location: INDIA
Distribution: CentOS, RHEL, Fedora, Debian, Ubuntu, LinuxMint, Kali Linux, Raspbian
Posts: 166

Rep: Reputation: 10
You missed it here

Quote:
if [ $NO_CNTRS_TO_INSPECT==1 ]
then
egrep -i "== clock|$2|$SHOWTECH_TO_INSPECT
Quote:
if [ $NO_CNTRS_TO_INSPECT==1 ]
then
egrep -i "== clock|$2|$SHOWTECH_TO_INSPECT"
by the way what are you trying to achieve by this script ? There are few mistakes in the script which need to fix before run it.
 
Old 09-21-2015, 02:42 AM   #3
networkguy
LQ Newbie
 
Registered: Sep 2015
Posts: 4

Original Poster
Rep: Reputation: Disabled
thank you

Actually I GUESS i didn't copy paste correctly

script still doesn't work

#!/bin/bash
echo "How many counters to inspect?"
read NO_CNTRS_TO_INSPECT
i=1
while [ $i -le $NO_CNTRS_TO_INSPECT ]
do
echo "Which Counter to inspect?"
read CNTR_TO_INSPECT$i
#echo CNTR_TO_INSPECT$i
((i++))
done
echo "Which showtech do you want to inspect?"
read SHOWTECH_TO_INSPECT
#egrep -i "== clock|$CNTR_TO_INSPECT" $SHOWTECH_TO_INSPECT



if [ $NO_CNTRS_TO_INSPECT==1 ]
then
egrep -i "== clock|$2|$SHOWTECH_TO_INSPECT”

else
if [ $NO_CNTRS_TO_INSPECT==2 ]
then
egrep -i "== clock|$2|$3|$SHOWTECH_TO_INSPECT"
else
echo "max 2"
fi
fi

..Just experimenting on finding deltas from a network device stat file

thank you!
 
Old 09-21-2015, 04:48 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
1. please post using CODE tags https://www.linuxquestions.org/quest...do=bbcode#code
2. indent your code
3. when comparing values, use the correct operators http://www.tldp.org/LDP/abs/html/comparison-ops.html
4. leave spaces around them
Code:
if [[ $x == "str" ]]
if [[ $y -eq 2 ]]
5. Use double brackets http://tldp.org/LDP/abs/html/testcon...ml#DBLBRACKETS
6. to debug, use
Code:
set -xv
at the top of your code after the hash-bang line
 
1 members found this post helpful.
Old 09-21-2015, 05:46 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
I am curious as to what either egrep line is trying to achieve? You appear to be grepping nothing.
 
Old 09-21-2015, 07:12 AM   #6
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
I am curious as to what the OP wants to achieve with his/her script!
 
  


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
Need help getting started simple simple shell script dhonnoll78 Programming 6 12-17-2007 05:34 PM
Simple Shell Script Error SBN Programming 11 03-19-2007 06:18 PM
Can't seem to run a simple shell script error command not found each time SimonT Linux - Newbie 5 10-29-2006 06:31 AM
Very Simple Shell Script cli_man Linux - Software 5 04-24-2003 10:14 AM
Simple C Shell script is not so simple elconde Programming 2 09-16-2001 11:53 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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