[SLUG] shell oddities

From: Eben King (eben1@tampabay.rr.com)
Date: Tue Jan 06 2004 - 11:56:00 EST


I have a couple scripts I wrote in pdksh. I just upgraded to RH8, and now
whenever ksh runs from trn, I get 'stty: standard input: Inappropriate
ioctl for device'. Can I fix that without rewriting it in a different
shell?

I started rewriting one of my scripts that gets called most often -- it
generates a random string of user-specified length, for use in filenames
or whatever. It's this:

#! /bin/ksh
typeset -i length="$1"
typeset -i 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)

I started rewriting it in bash, as this:

#! /bin/bash
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)

But the data never appears! The echo is executed (so says "set -x"). If
I add an echo after it, the buffer is flushed, but that defeats the point
of using "echo -n". What's wrong with this script? Thanks.

-- 
-eben    ebQenW1@EtaRmpTabYayU.rIr.OcoPm    home.tampabay.rr.com/hactar
GEMINI:  Your birthday party will be ruined once again by your explosive
flatulence. Your love life will run into trouble when your fiancee hurls a
javelin through your chest.  -- Weird Al, _Your Horoscope for Today_

----------------------------------------------------------------------- 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:28 EDT