Re: do shell script and full path to unix command
Re: do shell script and full path to unix command
- Subject: Re: do shell script and full path to unix command
- From: "Mark J. Reed" <email@hidden>
- Date: Thu, 17 Dec 2009 07:43:16 -0500
When run without a full path, the 'cd' command is not a program on
disk; it's built-in to the shell. For some reason, the shell builtins
all have links in /usr/bin to a single script that calls 'builtin'
followed by the command name, but I don't know what purpose that
serves.
The whole reason these commands are builtins is because otherwise they
could have no effect at all. When a command on disk is executed, it
is run as a brand-new process, and any changes to attributes
associated with a process's in-memory state (current working
directory, environment variables, shell aliases, etc.) go away when
that process exits. So when you run /usr/bin/cd, it does change the
working directory - but only in the new process that you just started,
which immediately exits.
In bash, instead of 'which', use the built-in command 'type' to find
out where a command comes from. It will tell you when a command is
builtin:
$ type cd
cd is a shell builtin
$ type ls
ls is /bin/ls
There's also a builtins(1) manual page (type "man builtins" in the
Terminal to read it), and the builtins are also listed in each shell's
documentation (info bash, etc).
Don't use a full path for builtin commands.
On Thu, Dec 17, 2009 at 6:56 AM, Hagimeno <email@hidden> wrote:
> Hi,
>
> as described in the tech note:
> http://developer.apple.com/mac/library/technotes/tn2002/tn2065.html
>
> is suggested to use the full path to unix command
>
> Second, when you use just a command name instead of a complete path, the shell uses a list of directories (known as your PATH) to try and find the complete path to the command. For security and portability reasons, do shell script ignores the configuration files that an interactive shell would read, so you don’t get the customizations you would have in Terminal. Use the full path to the command, for example, /sbin/ifconfig instead of just ifconfig. To find the full path in Terminal, say which command-name, for example, which ifconfig; to see the list of places do shell script will search, say do shell script "echo $PATH".
>
> Usually calling do shell script with full path, all works good with many commands.
> But using the cd command with full path:
> /usr/bin/cd /Users/adminosx/Music/iTunes
>
> don't switch dir.
>
> Is possible to know why?
>
> Alex and Steve
>
>
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> AppleScript-Users mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> Archives: http://lists.apple.com/archives/applescript-users
>
> This email sent to email@hidden
>
--
Mark J. Reed <email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden