Re: BASH: troubke using a function argument passed to awk to find major number
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Re: BASH: troubke using a function argument passed to awk to find major number




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Re: BASH: troubke using a function argument passed to awk to find major number  
Bill Marcum


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-15-05 11:05 PM

On Fri, 15 Jul 2005 11:44:40 -0400, Ho-Kuo Chan
<hchan@wavesat.com> wrote:
> Hi,
> 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 }'`
>
The problem is that you use single quotes, so the $1 representing the
function argument is not expanded.
MAJOR=`awk "/$1/ { printf \$1 }" /proc/devices`

MAJOR=`awk -v dev=$1 '$2~dev{printf $1}' /proc/devices`


--
Tonight you will pay the wages of sin; Don't forget to leave a tip.





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 12:29 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register