Re: execline: using cd in a script

From: Laurent Bercot <ska-skaware_at_skarnet.org>
Date: Mon, 19 May 2025 16:13:02 +0000

>As I discovered execline cd replaces the linux utility in a system and
>produces peculiar results

  It doesn't really replace it. 'cd' is always a shell builtin. If there
is a previous 'cd' binary on your system (Fedora still has one, maybe?),
it is never used, and only there for compliance with a silly POSIX
requirement.

  If you build execline with --enable-pedantic-posix, it can replace
that binary, yes, but it will not replace the 'cd' command that is
used by shell scripts.


>On console cd seems to be perfect as expected

  If you include 'cd' in a command line in a way that it has to be an
external command, it will work, whether in a terminal or in a script:
$ env cd /etc ls
will display the contents of /etc.

If you just run
$ cd /etc ls
then cd is your shell builtin and it will only change your cwd to /etc,
it will not run the ls command.


> on script #!/bin/sh
>when changing to a directory in a mounted partition it fails, while
>normal cd works as if it is on a single partition.

  This has nothing to do with partitions, or glibc, or gcc, or anything.
The only thing that can impact the result is whether or not a shell
is interpreting your 'cd' command.

  You should never need to access execline's cd binary as the first link
in a chainloading command line in a shell, since you can always use the
"cd foobar && rest_of_command..." construction. But if for some weird
reason you do, using "env cd" will do the trick.

--
  Laurent
Received on Mon May 19 2025 - 18:13:02 CEST

This archive was generated by hypermail 2.4.0 : Mon May 19 2025 - 18:13:36 CEST