Solved

Re:Cygwin Shell Script

Posted on 2009-05-14
7
446 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now