Unix Programming - Re: BASH: troubke using a function argument passed to awk to find major number

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > July 2005 > Re: BASH: troubke using a function argument passed to awk to find major number





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Re: BASH: troubke using a function argument passed to awk to find major number
joe@invalid.address

2005-07-15, 6:05 pm

Ho-Kuo Chan <hchan@wavesat.com> writes:

> I am a relative newbie to BASH programming but I've read and learned
> a lot but I can't seem to solve my problem. I am trying to figure
> out the major number of a device through cat /proc/devices piped to
> awk:
>
> cat /proc/devices | awk '/theDeviceName/ { printf $1 }'.
>
> I am trying to write a function that receives the device name as an
> argument:
>
> function find_major()
> {
> MAJOR=`cat /proc/devices | awk '/$1/ { printf $1 }'`
>
> # do some other work...
> }
>
> I have tried this:
> function find_major()
> {
> MAJOR=`cat /proc/devices | awk '/$1/ { printf \$1 }'`
>
> # do some other work...
> }
>
> and some other alternatives but just can't seem to get it to work. Can
> anyone help?


It would be easier and more portable to use a long directory listing
to get the device numbers.

#!/bin/bash
function find_major
{
set -- `ls -l $1`
echo ${5%,}
}

find_major /dev/tty

Joe
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com