Coding for Penetration Testers issue...

the_Grinchthe_Grinch Member Posts: 4,165 ■■■■■■■■■■
So I'm reading the book and following the examples, but I cannot get one of them to work. Doesn't appear to be an issue with my code and of course they don't offer anywhere for me to download the code to review. Hopefully someone here has been reading this book and might be able to offer me some guidance.

#!/bin/bash
If [ "$1" = "Neo..." ]; then
MESSAGE="Wake up, "$1
else
MESSAGE="Hey, you're not Neo"
fi
Echo $MESSAGE

I set it to be executable and get the following error...

[email protected]:~/Desktop/Scripts$ ./conditionals Neo...
./conditionals: line 2: syntax error near unexpected token `then'
./conditionals: line 2: `If ["$1" = "Neo..."]; then'
WIP:
PHP
Kotlin
Intro to Discrete Math
Programming Languages
Work stuff

Comments

  • WebmasterWebmaster Admin Posts: 10,292 Admin
    Edit: nvm that ;

    How about replacing MESSAGE with $MESSAGE ?
  • the_Grinchthe_Grinch Member Posts: 4,165 ■■■■■■■■■■
    Nope same error....thanks for the help!
    WIP:
    PHP
    Kotlin
    Intro to Discrete Math
    Programming Languages
    Work stuff
  • TeKniquesTeKniques OSCE, OSCP, CISSP, CISA, SSCP, MCSE (03), Security+, Network+, A+, Project+ Member Posts: 1,262 ■■■■□□□□□□
    Have you tried to remove the ; and put 'then' on another line?
  • AlexNguyenAlexNguyen Member Posts: 359
    the_Grinch wrote: »
    ./conditionals: line 2: syntax error near unexpected token `then'
    ./conditionals: line 2: `If ["$1" = "Neo..."]; then'

    Unix is case sensitive. Replace "If" with "if" in lowercase.
    Replace "Echo" with "echo" too.
    Knowledge has no value if it is not shared.
    Knowledge can cure ignorance, but intelligence cannot cure stupidity.
  • ipchainipchain Member Posts: 297
    I'm with AlexNyugen on this one. In addition, check the following link out: BASH Programming - Introduction HOW-TO: Conditionals

    Good Luck!
    Every day hurts, the last one kills.
  • the_Grinchthe_Grinch Member Posts: 4,165 ■■■■■■■■■■
    Yup, it was the caps that did it! I should I realized because I am using Kate to edit and create the scripts and the If wasn't bolded and the echo wasn't purple. Worse part is I typed it exactly as it appeared in the book....thanks guys!
    WIP:
    PHP
    Kotlin
    Intro to Discrete Math
    Programming Languages
    Work stuff
Sign In or Register to comment.