?
Solved

Re:Cygwin Shell Script

Posted on 2009-05-14
7
Medium Priority
?
453 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 2000 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
Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Suggested Courses

752 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