LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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

Reply
 
Search this Thread
Old 07-28-2007, 05:15 PM   #1
ocicat
Member
 
Registered: May 2007
Posts: 208

Rep: Reputation: 47
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.
 
Old 07-28-2007, 05:21 PM   #2
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 326Reputation: 326Reputation: 326Reputation: 326
while [ `df | grep $s$` ]
 
Old 07-28-2007, 05:28 PM   #3
ocicat
Member
 
Registered: May 2007
Posts: 208

Original Poster
Rep: Reputation: 47
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?
 
Old 07-28-2007, 05:39 PM   #4
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 326Reputation: 326Reputation: 326Reputation: 326
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 [ ]
 
Old 07-28-2007, 05:44 PM   #5
ocicat
Member
 
Registered: May 2007
Posts: 208

Original Poster
Rep: Reputation: 47
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Generate a random number from a bourne shell script lothario Linux - Software 2 03-01-2007 11:01 PM
for statement in bourne shell script bujecas Linux - General 3 07-17-2006 07:32 AM
file permissions in bourne shell script bujecas Linux - General 2 07-12-2006 11:46 AM
Help with basic bourne shell script rnj Programming 6 09-13-2005 08:41 PM
Bourne Script Help Needed JCScoobyRS Linux - General 4 03-03-2003 04:46 PM


All times are GMT -5. The time now is 05:42 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration