Re: [SLUG] shell oddities

From: Kwan Lowe (kwan@digitalhermit.com)
Date: Tue Jan 06 2004 - 18:48:15 EST


> That's odd. I tried it that way (through PuTTY), it worked, so I put it
> back, it worked. Heisenbug, I thought. So I went over to the machine.
> No output in rxvt or xterm. Works on the console. XFree86 bug?
>
> What does $[ ... ] signify? Like $(( ... )) in ksh?

I believe that $[ ... ] and $((...)) do the same thing. Your original
appeared to be missing an extra () so I didn't go further in your script.
Here's a run:

foo:
#!/bin/bash
set -x
length="$1"
let hex_bytes=$[ (${length}+1)/2 ]
echo -n $(dd if=/dev/random bs=$hex_bytes count=1 2> /dev/null \
| od --address-radix=none --format=x \
| tr -d ' \n' \
| cut -b 1-$length)

[kwan@gamma kwan]$ ./foo 10
+ length=10
+ let hex_bytes=5
++ dd if=/dev/random bs=5 count=1
++ od --address-radix=none --format=x
++ tr -d ' \n'
++ cut -b 1-10
+ echo -n 53e1facd00
53e1facd00

This was a run in an xterm. Maybe you can strace to see what's (not) occurring.

BTW, you can use the Bash $RANDOM envar for random digits. You'll need to do
some manipulation to get your hex characters, but this might be easier than
using /dev/random.

-- 
* The Digital Hermit   http://www.digitalhermit.com
* Unix and Linux Solutions   kwan@digitalhermit.com
-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS).  Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 20:12:53 EDT