Solved

Re:Cygwin Shell Script

Posted on 2009-05-14
7
445 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sum67 challenge 35 89
Backing Up Ipset 9 65
EXCHANGE, ACTIVE DIRECTORY 4 58
Powershell script explanation 10 43
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.

708 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

18 Experts available now in Live!

Get 1:1 Help Now