Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

using a shell variable in Cygwin (windows unix equivalent)

Posted on 2006-05-20
4
Medium Priority
?
306 Views
Last Modified: 2010-04-21
Hi,

I'm trying to set a variable in a Cygwin shell script.    I try the following:

find . -name "*.pro" | while read filename
do
set V = $filename
set V = `echo $filename`
echo $V
echo ${V}
...

and I've tried a bunch of variations on the set theme, but the echo $V always gives a blank value.

How do I assign a variable in a script?
Thanks,
Gene

0
Comment
Question by:ugeb
  • 3
4 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 16725229
Hi ugeb,

There should be no space on either side of =

Cheers!
Sunnycoder
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 16725238
> set V = $filename
          V=$filename
          ^^^ Note there are no spaces on either side of =

Cheers!
Sunnycoder
0
 
LVL 11

Author Comment

by:ugeb
ID: 16725349
Hi,

Okay, I tried your suggestion:

1)  
echo $filename | awk 'BEGIN {FS="/"} {print substr($0,1,length($0)-4) "4.pro"}'

2)  
  set V=`echo $filename | awk 'BEGIN {FS="/"} {print substr($0,1,length($0)-4) "4.pro"}'`
  echo  $V

 #1 echos what I'm looking for, but  #2 (when I'm trying to put it in a variable) doesn't.  Is there some difference between Cygwin shell and unix shell maybe?
Thanks,
Gene

0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 2000 total points
ID: 16725358
You do not need set

V=`echo $filename | awk 'BEGIN {FS="/"} {print substr($0,1,length($0)-4) "4.pro"}'`
echo  $V
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

810 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