coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

New utility suggestion: chdir(1)


From: Colin Watson
Subject: New utility suggestion: chdir(1)
Date: Sat, 26 Aug 2017 19:10:28 +0100
User-agent: NeoMutt/20170113 (1.7.2)

I would like there to be an adverbial version of "cd", which takes a
path followed by a command and optional arguments and executes the
command with its working directory set to the given path.  Its
invocation would be similar to chroot(8), that is:

  chdir [OPTION] NEWDIR [COMMAND [ARG]...]

This would allow these two commands to be synonyms aside from a
different arrangement of processes:

  (cd /foo && ls -l)
  chdir /foo ls -l


Why do I want this when there's a perfectly good shell builtin?  Well, I
often find that I want to write programs that take an argument list and
run them in various different contexts, for example in a chroot (using
"chroot") or in a container (using "lxc exec").  Unless the
context-entering command has an option to set the current directory -
neither of the two aforementioned examples does - I have to do this by
writing something along the lines of:

  sudo chroot /path/to/chroot sh -c 'cd /foo && ls -l'

This means dealing with shell quoting, which is tedious and error-prone.
It would be much easier if I had something that composed nicely with
other programs that use this kind of pattern for running a child process
in some different context:

  sudo chroot /path/to/chroot chdir /foo ls -l


If people think this is a reasonable idea then I'd be happy to write the
code, although I'd have to faff around with getting my employer to sign
a copyright assignment.  I'm aware that (as far as I know) this is an
innovation rather than something that other operating systems already
implement; I think my suggested name is the most natural choice by
analogy with the system call and chroot(8).


Thanks,

-- 
Colin Watson                                       [address@hidden]



reply via email to

[Prev in Thread] Current Thread [Next in Thread]