bug-coreutils
[Top][All Lists]
Advanced

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

Re: Command touch and irregular file names


From: Brian Dessent
Subject: Re: Command touch and irregular file names
Date: Wed, 15 Aug 2007 01:05:34 -0700

- Tong - wrote:

> In my script I have
> 
>  touch -r "$file1" "$file2"
> 
> the file1/2 can be anything file, ../path/file, /root/file, etc.
> 
> The problem is when file1/2 are irregular file names. E.g., -test.file1/2.
> 
> I.e., anyway to make the following touch command works?
> 
>  $ touch -r "-test.file1" "-test.file2"
>  touch: invalid date format `est.file2'

You can do:

$ touch -r ./-test.file1 -- -test.file2

If you want to automate this from the script I suppose you could try
something like:

touch -r "$(readlink -f -- "$file1")" -- "$file2"

That is, express file1 with a full pathname, and -- should work for
$file2 since it is a non-option argument.

> I think if the touch command uses the standard gnu getopt lib, then
> the above code should work, shouldn't it?

I don't think it should.  It would require much more context for a
generic options parser to speculatively treat certain groupings of
options as filenames, test for existance of those files, and change
behavior dynamically.  That kind of thing would be rife with corner
cases, unexpected outcomes (e.g. -file names a filename that's not
supposed to exist), maintenance nightmares, etc.

Brian




reply via email to

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