?
Solved

Re:Cygwin Shell Script

Posted on 2009-05-14
7
Medium Priority
?
455 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 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Utilizing an array to gracefully append to a list of EmailAddresses
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…
Suggested Courses

850 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