Solved

Re:Cygwin Shell Script

Posted on 2009-05-14
7
451 Views
Last Modified: 2013-12-26
Trying to learn how to write a unix shell script. Using cygwin.  When executing the
script, I get an error that reads  

line 11 command not found

If I enter the text that makes the statement true, the script does not error, if the input is
false, I receive an error line 11 command not found.  Below is the code.

# Author: 
# Script Name:lscript
# Description:
# Date:
 
echo "What is your name ?"
 
read name
 
 
if $name ='test'
then
echo "Same Name"
else
echo "Different Name"
fi

Open in new window

0
Comment
Question by:RJDPCRRPTS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 29

Accepted Solution

by:
MikeOM_DBA earned 500 total points
ID: 24387774
Try this:
 

# Author: 
# Script Name:lscript
# Description:
# Date:
echo "What is your name ?"
read name
if [ "$name" = 'test' ]
then
  echo "Same Name"
else
  echo "Different Name"
fi

Open in new window

0
 

Author Comment

by:RJDPCRRPTS
ID: 24388891
The actual file is copied to c:\cygwin\bin

When I login, I'm at my home directory


I tried the script you mentioned and I still get command not found
The message says something to the effect \usr\bin command not found
Is this because of where the script is running from or how I'm logging in to cygwin ?

0
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 24389179
Are you using the cygwin.bat file to start cygwin?
This "bat" file should look like this:
 

rem cygwin.bat
@echo off
C:
chdir C:\cygwin\bin
bash --login -i

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:RJDPCRRPTS
ID: 24389359
I'll check on this and post back.  
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 24393895
If you hadn't chosen the name 'test' (which is also a shell builtin), your script would always fail, regardless of whether the 'if' statement would theoretically become true or not.
This is due to the missing brackets ( [  ] ) in your 'if' test. MikeOM_DBA's solution should work perfectly!
You should post the modified script, so we can check it.
btw. the error has in no way to do with paths, as you only use shell builtins (read, echo, if, then, else, fi)
wmp
 
0
 

Author Comment

by:RJDPCRRPTS
ID: 24396182
I retried the script. It worked. I did not have a space after the first bracket and before the last bracket in the if statement. Thank you for your help.
0
 

Author Closing Comment

by:RJDPCRRPTS
ID: 31581457
Thank you for the timely response.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question