![]() |
|
[Shell] syntax error unexpected end of file - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Shell] syntax error unexpected end of file (/showthread.php?tid=5479972) |
syntax error unexpected end of file - Exsanity - Nov 30, 2016 So i have asked on discords for help as well and figured i'd take it to the forums i read that it might be due to mismatch if and fi or done without a for and all that but i tried putting fis and din't work might of put them in the wrong place but the exact error i am getting is: line 38: syntax error: unexpected end of file I am new to batch (like legit 2 days) so excuse my beginner mistake(s) My Code: #!/bin/bash echo "This program is meant only for simple and educational/personal uses" echo "choose what you want!" :menu echo "[1] Check for Certain Port" echo "[2] Scan all Open Ports" echo "[3] Scan Tool" echo "[4] Close the Program" echo set /p mc="What would you like to do: " if %mc%==1 goto 1 if %mc%==2 goto 2 if %mc%==3 goto 3 if %mc%==4 goto 4 if %mc% > 4 || %mc% < 1 echo Invalid Number Entered you entered %mc% not 1 - 4 try agin goto menu :1 echo Not Set Up Yet goto menu :2 echo Not Set Up Yet goto menu :3 echo work or some shit if exist %userprofile%\Desktop\%NSL%_info.txt del %userprofile%\Desktop\%NSL%_info.txt set /p NSL="Enter IP: " echo Scanning %NSL% > %userprofile%\Desktop\%NSL%_info.txt nslookup %NSL% echo All of this info will be placed on your desktop wait 9 goto menu :4 echo Closing... exit * - SIMMS7400 - Nov 30, 2016 You have bash and batch code in the same file. What is your purpose? To declare a variable in batch you use: SET VAR1=Hi ECHO %HI% In Shell: VAR1=Hi ECHO $VAR1 I'm going to bet you haven't the slightest clue. * - b00st3d - Nov 30, 2016 First, put all code in a tag as seen below (remove the space) please. [ code]your script here[/code] Remove #!/bin/bash this is just for bash scripts in linux Top line should be as follows to remove the commands and just output what you have echo'd Code @echo offThis line wont work. Just remove it. If it gets to the line, then an invalid selection was made. Code if %mc% > 4 || %mc% < 1instead of wait 9, use timeout 9 Feel free to ask more questions and hang around the forums. Someone here can help you out. Fixing Post Issues - Exsanity - Nov 30, 2016 for some reason quotes aren't working on the forums but i did both of your solutions Indeed i did not know, i guess i was reading the wrong book! Thank you for your correction and excuse my mistake! After doing this change and making all the %mc% and %NSL% etc into just $mc $NSL etc i still receive the syntax error for some reason quotes aren't working on the forums but i did both of your solutions Done this as well as read above^ and the error persists New code: @echo off echo "This program is meant only for simple and educational/personal uses" echo "choose what you want!" goto menu :menu echo "[1] Check for Certain Port" echo "[2] Scan all Open Ports" echo "[3] Scan Tool" echo "[4] Close the Program" echo set /p mc="What would you like to do: " if $mc==1 goto 1 if $mc==2 goto 2 if $mc==3 goto 3 if $mc==4 goto 4 :1 echo Not Set Up Yet goto menu :2 echo Not Set Up Yet goto menu :3 echo work or some shit if exist $userprofile$\Desktop\$NSL$_info.txt del $userprofile$\Desktop\$NSL$_info.txt set /p NSL="Enter IP: " echo Scanning $NSL > $userprofile\Desktop\$NSL_info.txt nslookup $NSL echo All of this info will be placed on your desktop timeout 9 goto menu :4 echo Closing... exit For some reason quotes and anything BB such as spoilers and code tags etc won't work! * - b00st3d - Nov 30, 2016 (Nov 30, 2016 06:49 AM)Exsanity Wrote: ... You are mixing up your scripting enviroments. Is this for linux or windows? Nevermind the error you mention is definitely a linux error. I'm downloading linux mint to test on but I re-wrote your script as a shell script. It doesn't want to run in the windows 10 bash for some reason. OK this is verified working on linux. Take note of the comments I used and the layout. Shell scripting likes to work similar to programming languages with functions called by the main script. In this case I wrote everything into it's own function then called the menu at the bottom of the script. All functions point back to the menu when the complete. There are some logic errors in the scan tool that I left in there. Logic errors means it will still run but it probably wont function as expected ie. you check for the existance of a file with a variable in the filename that is not defined. It will of course not exist unless you run the scan tool twice during the same instance of running the script. Code #! /bin/bash |