This is the mail archive of the mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [ITP] shellsupport-1.2.4-1

On Sun, 10 Oct 2004, Reini Urban wrote:

I want to maintain shellsupport, a simple (bourne) shell scripting
support helper. It is a commandline C program that provides those
features I miss when writing portable shell scripts, because they are
not covered by other portable (Posix 1003.2) tools.

Hmm, I don't see much need for a package like this in Cygwin, frankly, as most of the functionality *can* be accomplished using existing means. See below.

$ shellsupport -h
-t s                    print seconds since 1970 for current time

date +"%s"

-t s <datespec>         print seconds since 1970 for <datespec>
   supported formats (only C locale, no national locales!):
      date(1)           Tue May 16 17:10:19 MEST 2000

date +"%a %b %d %T %Z %Y"


date +"%c"

if you don't want a timezone indicator

apache-log 16/May/2000:17:07:01

date +"%d/%B/%Y:%H:%M:%S"

ISO-8601 short 20000516T151152

date +"%Y%m%dT%H%M%S"

Random U.S. crap 02-21-1999 02:31 PM (month first, 12h)

date +"%m-%d-%Y %I:%M %p"

-t d <seconds>          print date(1)-format for 1970+sec
-t a <seconds>          print apache-format for 1970+sec
-t i <seconds>          print ISO-8601 short for 1970+sec
-t u <seconds>          print Unix-like CCYYMMDDhhmm.SS for 1970+sec

These are harder, as I've found no way of converting the seconds number back to the date other than invoke, say, perl... However, I'm going to guess that most of these are used for converting the output of the following three invocations to date format, so...

-f a <file> file access date in secs from 1970

ls --full-time --time=access <file> | cut -c44-67 | date +"%s" -f-

-f c <file> file status date in secs from 1970

ls --full-time --time=status <file> | cut -c44-67 | date +"%s" -f-

-f m <file> file modification date in secs from 1970

date +"%s" -r <file>


ls --full-time <file> | cut -c44-67 | date +"%s" -f-

-f l <symlink> print target of symbolic link

readlink <symlink>

-f P <file> <blocksz> Pad file to blocksize with zeros

Can't "dd" do this? And even if it can't, why would you ever do this?

-f w <file> wipeout (overwrite with zeros)

Again, can't "dd" do this?

-c count from 1

Eh? From 1 to what? An infinite sequence?

-c <n> count from 1 to <n>

seq 1 <n>

-c <n> <m> count from <n> to <m>

seq <n> <m>

   if <n> has a leading zero, all number will have zeros in front
   so that the length of each number is that of <m> (not <n>)

seq -w <n> <m>

-c <n> <m> <o> dito, with step <o> (may be negative)

seq <n> <o> <m>

(and there's a typo above, should be "ditto").

-r i random integer between 0 and 2147483647

od -td4 -N4 /dev/random | sed 's/^[0-9]\+ *-\?//'

or, if you want unsigned random in the range of 0 to 4G,

od -tu4 -N4 /dev/random | awk '{print $2}'

-r i <n> random integer number between 0 and <n>

expr `od -tu4 -N4 /dev/random | awk '{print $2}'` % <n+1>

or even

od -tu4 -N4 /dev/random | awk '{if(NR==1){print $2 % <n+1>}}'

-r f                    random float between 0.0 and 1.0
-r f <f>                random float between 0.0 and <f>

Ugh, in what format? In any case, you can use

od -tf8 -N8 /dev/random | awk '{if(NR==1){print $2}}'

to get a random float, and do what you will with it, or even something

awk '{print rand()}'
awk '{print rand() * <f>}'

(use printf to get the desired output format).

-r a <arguments ...> echo arguments in random order

Again, this isn't easily achieved by other means, but *why* would one want to use this? FWIW,

echo "$@" | awk '{OFS="\n";$NF=$NF;print}' | awk '{printf "%7.5f %s\n", rand(), $0}' | sort -n | sed 's/^[0-9.]\+ //'

assuming args don't contain spaces.

-r a as before, but use * (without dirs)

Heh, even easier:

ls -1p | grep -v '/$' | sed 's/[@=|]$//' | awk '{printf "%7.5f %s\n", rand(), $0}' | sort -n | sed 's/^[0-9.]\+ //'

I'll be glad to be proven wrong,
     |\      _,,,---,,_
ZZZzz /,`.-'`'    -.  ;-;;,_
    |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
   '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"Happiness lies in being privileged to work hard for long hours in doing
whatever you think is worth doing."  -- Dr. Jubal Harshaw

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]