Re: How to change file's timestamp?

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

 



On Tue, 22 Aug 2006 10:56:11 -0500 (CDT), Hongwei Li wrote:
The problem is when I run it at command line, it works, but not in the script:

# touch --date="Tue Aug 22 08:30:00 CDT 2006" t1
works well. However, the script mystmp:

#!/bin/sh
newstmp=$1
touch --date=$newstmp t1

and run mystmp as:
# ./mystmp "Tue Aug 22 08:30:00 CDT 2006"

didn't do what I want, but created:

# ls -l
total 32
-rw-r--r-- 1 root root   0 Aug 22 00:00 08:30:00
-rw-r--r-- 1 root root   0 Aug 22 00:00 2006
-rw-r--r-- 1 root root   0 Aug 22 00:00 22
-rw-r--r-- 1 root root   0 Aug 22 00:00 Aug
-rw-r--r-- 1 root root   0 Aug 22 00:00 CDT
-rwxr-xr-x 1 root root 420 Aug 22 10:47 mystmp
-rw-r--r-- 1 root root   0 Aug 22 00:00 t1

What's wrong? Thanks!

The problem is that the parameter has spaces within it, so when you use that as
a variable within your script, you need to enclose it with quotes. Your script
currently expands that command to something such as:

	touch --date=Tue Aug 22 08:30:00 CDT 2006 t1

which - since the "Aug," "22," "08:30:00," etc files don't exist - creates them
and sets their timestamps to the current time. You need to use --date="$1" so
that the command is interpreted as you had intended:

	touch --date="$1" foo.file

That would expand to something such as:

	touch --date="Tue Aug 22 08:30:00 CDT 2006" foo.file

which is what I believe you are intending to do.

Hope that helps.
--
Peter Gordon (codergeek42)
This message was sent through a webmail interface,
    thus has no digital signature.

--
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux