• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Pipes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Pipes


  • Subject: Re: Pipes
  • From: "Marc K. Myers" <email@hidden>
  • Date: Sun, 11 Jan 2004 01:39:15 -0500

These are being used in shell scripts that I use to find matching processes in "ps" listings and matching files in "ls" listings. The first is "cprc" ("see processes") and the second is "cfle" ("see files"). Each is invoked with a single argument which is the string to be matched in the listing.

There's probably a way to debug what's going on inside a shell script but I haven't figured it out yet.

Marc [01/11/04 1:24:25 AM]

Date: Sun Jan 11, 2004 12:56:05 AM America/Detroit
To: "Marc K. Myers" <email@hidden>
Cc: email@hidden
Subject: Re: Pipes

First of all, "$1" resolves to a variable named 1. Doing [2] gives me a listing of everything in the working directory, to find out why I checked what $1 was set to by doing:
echo "$1"

It turned out that the variable $1 was set to a linefeed and was thus matching every line from the ls command.

If you want to search for a literal $1 you should do this:
ls -la | grep -i '\$1'

You need the \ before the $ because a $ is a metacharacter that represents the end of the line in a regular expression and so the \ escapes that metacharacter and makes it into a normal dollar sign.

So basically things are most likely acting screwy because you are running into some murky waters where things are a bit undefined. What is it that you are trying to grep here? If you explain what pattern you are trying to match then we can see what is best to use.

- Ken

On Jan 10, 2004, at 11:44 PM, Marc K. Myers wrote:

Could someone tell me why this works:

[1] ps -acx | grep -i "$1"

and this doesn't?

[2] ls -la | grep -i "$1"

This *will* work:

[3] ls -la | grep -i "${1}"

and this will work

[4] ps -acx | grep -i "${1}"

but I can't figure out why [2] won't.

Marc [01/10/04 11:43:56 PM]
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Pipes
      • From: Graff <email@hidden>
    • Re: Pipes
      • From: Juan Fuentes <email@hidden>
    • Re: Pipes
      • From: Stevan Reese <email@hidden>
References: 
 >Re: Pipes (From: Graff <email@hidden>)

  • Prev by Date: Re: Pipes
  • Next by Date: Re: Selection in iPhoto
  • Previous by thread: Re: Pipes
  • Next by thread: Re: Pipes
  • Index(es):
    • Date
    • Thread