On Sat, Dec 18, 2010 at 01:48, Alex Schuster <wonko@xxxxxxxxxxxxx> wrote: > Dotan Cohen writes: > >> On Fri, Dec 17, 2010 at 20:30, Alex Schuster <wonko@xxxxxxxxxxxxx> wrote: >>> Yes. Something like this (untested): >>> >>> #!/bin/bash >>> >>> while (( $# )) >>> do >>> Â Â Â Âdate=$( ls -l --full-time "$1" | >>> Â Â Â Â Â Â Â Âawk '{ print $6" "$7 }' | >>> Â Â Â Â Â Â Â Âsed 's/.00000*//g' ) >>> Â Â Â Âiconv -f CP1255 -t UTF-8 "$1" > "$1-utf8" >>> Â Â Â Âtouch -d "$date" "$1-utf8" >>> Â Â Â Âshift >>> done >> >> Thanks. I have some googling to do, but I'll ask anyway: >> >> >>> while (( $# )) >> Does this mean to go through each CLI argument, something like foreach? > > Right. $# is the number of command line arguments, and (( x )) is true > when $x is != 0. Alternatively, you could as well do it like this: > > for file in "$@" > do > Â Â Â Â# and use "$file" instead of "$1" (the first argument) > done > >> What does the "shift" line do? > > It discards the first argument, and rotates the others. $2 becomes $1, > $3 becomes $2, and so on. > >>> Â Â Â Âdate=$( ls -l --full-time "$1" | >>> Â Â Â Â Â Â Â Âawk '{ print $6" "$7 }' | >>> Â Â Â Â Â Â Â Âsed 's/.00000*//g' ) >> This is pure genius, I was wondering exactly how difficult it would be >> to get this info into a variable in the format that touch would use. > > This looks more complicated than it is. ls -l --full-time gives the full > time of the file, and awk then outputs columns 6 and 7, which give date > and time. The time also has the fraction of seconds, which the touch > command will not understand, so we need the sed statement which replaces > the dot and a sequence of zeroes with an empty string. Actually, I made > a mistake, the dot needs to be escaped with a backslash, as a simlpe dot > matches every character, similar to a questionmark in file specifications. > >>> If you want to replace the files, you could proabaly use recode, which keeps >>> the time unless told otherwise: >>> Exec=recode CP1255..utf8 %f >> >> Actually, this is _exactly_ what I need. Thanks! > > I thought so, but then I had already written the code :) > > Glad I could help, > > Â Â Â ÂWonko Thanks. It took me some time to get to it, but the explanation was very helpful. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com ___________________________________________________ This message is from the kde mailing list. Account management: https://mail.kde.org/mailman/listinfo/kde. Archives: http://lists.kde.org/. More info: http://www.kde.org/faq.html.