• 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: Integrating Unix scripting in Cocoa app
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Integrating Unix scripting in Cocoa app


  • Subject: Re: Integrating Unix scripting in Cocoa app
  • From: Sherm Pendley <email@hidden>
  • Date: Tue, 7 Aug 2007 07:52:28 -0400

On Aug 7, 2007, at 6:38 AM, Ron Fleckner wrote:

My app has a Scripts menu from which the user can run Ruby, Python, Perl and AppleScripts. I want to be able to support shell and other script types and to do so, I need to get the shebang line from the script file and pass that to NSTask.

You don't need to know anything about the shebang line to execute a script with NSTask. Just launch the script directly as an executable, and the kernel will read the shebang line to determine out what interpreter to use.


This is by design, so that a parent process doesn't need to know or care what language a script uses, or even whether a child process is a script or a compiled binary. Worrying about that kind of specific implementation details is the kernel's job.

This really has nothing to do with Cocoa, by the way - it's true whether you use NSTask, system(), or any other API to launch the child process.

My question: Do people ever write shell scripts without a shebang line

Yes, but it's rare because they can no longer be executed directly. Instead, the interpreter is launched as the executable, and the path to the script given as an argument - i.e. "sh foo.sh" instead of just "./foo.sh".


or where the shebang line is NOT the first line of the script?

The shebang is by definition only found on the first line. The same text is just an ordinary comment if it's found anywhere else.


sherm--

Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Integrating Unix scripting in Cocoa app
      • From: Ron Fleckner <email@hidden>
References: 
 >Integrating Unix scripting in Cocoa app (From: Ron Fleckner <email@hidden>)

  • Prev by Date: Re: NSManagedObject temporary instance attribute
  • Next by Date: Re: Integrating Unix scripting in Cocoa app
  • Previous by thread: Re: Integrating Unix scripting in Cocoa app
  • Next by thread: Re: Integrating Unix scripting in Cocoa app
  • Index(es):
    • Date
    • Thread