coreutils
[Top][All Lists]
Advanced

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

Re: [PATCH] md5sum: add an option to change directory


From: Kaz Kylheku (Coreutils)
Subject: Re: [PATCH] md5sum: add an option to change directory
Date: Wed, 20 May 2020 18:26:59 -0700
User-agent: Roundcube Webmail/0.9.2

On 2020-05-20 14:15, Bertrand Jacquin wrote:
In the fashion of make and git, add the ability for all sum tools to
change directory before reading a file.

  $ sha256sum /etc/fstab
b5d6c0e5e6bc419b134478ad7b3e7c8cc628049876a7772cea469e81e4b0e0e5 /etc/fstab

Make requires this option because it reads a Makefile, and those often
contain relative references which assume that the Makefile's directory
is current.

The inputs to md5sum don't don't contain path references that break.

In other regards, every tool that does anything with files could
have a -C option:

Copying files:

    cp -C /etc fstab fstab.bak

Executing a script:

    sh -C /etc rc.local

Editing:

    vi -C /etc fstab

Where does it end?

  $ sha256sum -C /etc fstab
b5d6c0e5e6bc419b134478ad7b3e7c8cc628049876a7772cea469e81e4b0e0e5 fstab

The net effect is that just the output has changed to omit the path name.

Maybe this wants to be a --strip or -p option like with diff or patch,
or --basename-only to strip a variable number of components, leaving only
the last.

If I want to print a simplified name, I don't want to do this:

   md5_short()
   {
      local dir=$(dirname "$1")
      local base=$(basename "$1")
      md5sum -C "$dir" "$basename"
   }

   md5short /path/to/whatever

I just want this:

   md5sum --basename /path/to/whatever

The -C functionality can easily be done with subshells, or with a chdir()
after fork(), before exec():

In a script, instead of "make -C dir", you can always do (cd dir; exec make).

In C, make yourself a spawning function that has the dir-changing functionality
built in:

   spawn_program(path_to_executable, /* or let PATH be searched */
                 change_to_this_directory,
                 use_these_args,
                 these_env_vars);




reply via email to

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