LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 07-08-2017, 06:02 PM   #1
barakolshe
LQ Newbie
 
Registered: Jun 2017
Posts: 7

Rep: Reputation: Disabled
Help in bash script


Hello, I am trying to write a basic script in bash, but unfortunately it has an error that i can't seem to understand.
This is the script:
#!/bin/sh

i = 2
line = $(echo "UoMYTrfrBFHyQXmg6gzctqAwOmw1IohZ $i" | nc localhost 30002 | head -3 | tail -1)
if ("$line" = "Wrong! Please enter the correct pincode. Try again.")
then
echo "$line" > password.txt
fi

The error is:
./dump.sh: 3: ./dump.sh: i: not found

Thanks in advance for the help
 
Old 07-08-2017, 06:12 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 23,943

Rep: Reputation: 7028Reputation: 7028Reputation: 7028Reputation: 7028Reputation: 7028Reputation: 7028Reputation: 7028Reputation: 7028Reputation: 7028Reputation: 7028Reputation: 7028
Quote:
Originally Posted by barakolshe View Post
Hello, I am trying to write a basic script in bash, but unfortunately it has an error that i can't seem to understand.
This is the script:
Code:
#!/bin/sh

i = 2
line =  $(echo "UoMYTrfrBFHyQXmg6gzctqAwOmw1IohZ $i" | nc localhost 30002 | head -3 | tail -1)
if ("$line" = "Wrong! Please enter the correct pincode. Try again.")
then
    echo "$line" > password.txt
fi
The error is: ./dump.sh: 3: ./dump.sh: i: not found
First, please use CODE tags around your scripts. Secondly, the error is telling you very plainly that the error is on line 3, and goes on to tell you that it's complaining about "i"...which is on line 3 where you have "i = 2". Check out the bash scripting tutorials about defining variables, and about declaring the proper variable types. Try removing the spaces between the = sign, like "i=2".
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-5.html
http://tldp.org/LDP/abs/html/declareref.html
 
Old 07-08-2017, 06:12 PM   #3
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,513

Rep: Reputation: 1010Reputation: 1010Reputation: 1010Reputation: 1010Reputation: 1010Reputation: 1010Reputation: 1010Reputation: 1010
Maybe take the spaces out of i = 2.

Sorry, I was writing while TBone was posting.

Last edited by AwesomeMachine; 07-08-2017 at 06:14 PM.
 
1 members found this post helpful.
  


Reply

Tags
bash, script


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 - What am I doing wrong in this test? - BASH Script BW-userx Programming 34 04-08-2017 01:36 PM
[SOLVED] Bash Script - Reading User Input while Processing output from Command within Bash cleeky Linux - General 5 05-27-2014 02:57 PM
[SOLVED] Converting Script from Linux (GNU) Bash 4 to Solaris Bash 2.05 - Any cheat sheet? oly_r Solaris / OpenSolaris 6 05-03-2013 08:25 AM
SSH connection from BASH script stops further BASH script commands tardis1 Linux - Newbie 3 12-06-2010 08:56 AM
[SOLVED] Using a long Bash command including single quotes and pipes in a Bash script antcore Linux - General 9 07-22-2009 11:10 AM

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

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