Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
07-28-2007, 05:15 PM
|
#1
|
|
Member
Registered: May 2007
Posts: 206
Rep:
|
unexpected operator/operand in Bourne script
I'm still new to writing Bourne shell scripts, but the following has me stumped.
Code:
#!/bin/sh
s=/etc/X11/xinit
# find partition of directory
while [ `df | grep $s$` ]
do
s=`dirname $s`
done
echo $s
Upon execution, I'm getting the error unexpected operator/operand. What am I missing?
Thanks.
|
|
|
|
07-28-2007, 05:21 PM
|
#2
|
|
Senior Member
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,591
|
while [ `df | grep $s$` ]
|
|
|
|
07-28-2007, 05:28 PM
|
#3
|
|
Member
Registered: May 2007
Posts: 206
Original Poster
Rep:
|
Quote:
|
Originally Posted by macemoneta
while [ `df | grep $s$` ]
|
I thought the terminating '$' constrains the regular expression to match only at the end of the line. Is this wrong?
|
|
|
|
07-28-2007, 05:39 PM
|
#4
|
|
Senior Member
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,591
|
If that's what you want, then to insure proper evaluation use:
while [ `df | grep "${s}$"` ]
However, going one step further, you'll find that your command evaluates to a null string, which causes the while to fail.
Run this at the command line:
df
Do you see the string "/etc/X11/xinit" anywhere? What happens when the command evaluates to a null? You get:
while [ ]
|
|
|
|
07-28-2007, 05:44 PM
|
#5
|
|
Member
Registered: May 2007
Posts: 206
Original Poster
Rep:
|
Quote:
|
Originally Posted by macemoneta
What happens when the command evaluates to a null? You get:
while [ ]
|
I was thinking that `df | grep ${s}$` would provide the return code from grep. Thanks for clearing that up.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 04:58 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|