• 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: Multi-line do shell script. How?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multi-line do shell script. How?


  • Subject: Re: Multi-line do shell script. How?
  • From: Christopher Nebel <email@hidden>
  • Date: Thu, 22 Apr 2004 12:37:55 -0700

On Apr 22, 2004, at 5:42 AM, Doug McNutt wrote:

At 00:14 -0400 4/22/04, Graff wrote:
Ahh ok. I'm mostly a tcsh person so I'm used to using setenv. I got the "declare" command from the bash man pages and when I tested the command it did give me a listing of all my environment variables so I figured that was it.

bash and sh are links to the same executable module. My understanding is that, when called as sh, bash behaves in a manner compatible with the "original" UNIX shell. Perhaps declare is a bash-only call.

I didn't check carefully enough before claiming "declare" wouldn't work -- it does. Theoretically, bash emulates sh when invoked as "sh", but it still allows bash-isms where they don't conflict. Whether or not this is a bug depends on your perspective, but I'd guess that the GNU folks are unlikely to change it.

It's still not clear to me just how AppleScript calls "the" shell and what commands and environment variables are actually available. Actually learning sh/bash would probably help. A tech note that says it calls "sh" is precise, but one still wonders "which sh?" when there are user defaults and the English-like nature of AppleScript to consider.

Quoting from TN2065:

Q: What shell does do shell script use, really?
A: do shell script always calls /bin/sh. However, in Mac OS X, /bin/sh is really a copy of another shell that emulates sh. In 10.2 and later, this is bash; prior to that it was zsh.

Is that clear enough for you? AppleScript invokes your command by calling execve("/bin/sh", { "sh", "-c", your-command }, *(_NSGetEnviron())). That means that the sh process gets the environment of the host application (i.e., the one you told to "do shell script"). Because it is invoked as a non-interactive, non-login shell, it does not execute /etc/profile or ~/.profile, and because it's invoked as sh, it does not attempt to execute any other startup files. See sh(1) under the INVOCATION section for all the details.


--Chris Nebel
AppleScript Engineering
_______________________________________________
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.


References: 
 >Multi-line do shell script. How? (From: Simon Forster <email@hidden>)
 >Re: Multi-line do shell script. How? (From: Graff <email@hidden>)
 >Re: Multi-line do shell script. How? (From: Christopher Nebel <email@hidden>)
 >Re: Multi-line do shell script. How? (From: Graff <email@hidden>)
 >Re: Multi-line do shell script. How? (From: Doug McNutt <email@hidden>)

  • Prev by Date: Re: How to use "do shell script" to search for RegExps
  • Next by Date: Re: Out of the stone age
  • Previous by thread: Re: Multi-line do shell script. How?
  • Next by thread: Re: Multi-line do shell script. How?
  • Index(es):
    • Date
    • Thread