LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   rc.wireless tr error ? (https://www.linuxquestions.org/questions/slackware-14/rc-wireless-tr-error-4175422826/)

zithro 08-18-2012 06:38 PM

rc.wireless tr error ?
 
Hello,

I just installed Slack 13.37 on my laptop. Happy me :)

When reading the boot log, I realized there may be a little 'bug' in the rc.wireless file, causing an error 'tr: extra operand [A-F]'.
The buggy command is :
Code:

# Get the MAC address for the interface
HWADDR=`/sbin/ifconfig ${INTERFACE} | sed -ne 's/.*\(..:..:..:..:..:..\).*/\1/p' | tr [a-f] [A-F]`

Its not really a bug as nothing is impacted, but yet, I get this error message. When executing this command in bash though, no error is reported, i get my MAC uppercased.

So I read the tr man, then the "info coreutils 'tr invocation'", and here's what I read:
Quote:

GNU `tr' does not support the System V syntax that uses square brackets to enclose ranges. Translations specified in that format sometimes work as expected, since the brackets are often transliterated to themselves. However, they should be avoided because they sometimes behave unexpectedly. For example, `tr -d '[0-9]'' deletes brackets as well as digits.
I have two questions:
- shouldn't the brackets be removed from the command in rc.wireless ? Even going further, shouldn't the command be tr abcdef ABCDEF ?
- why is this command interpreted differently at boot time and in bash ?
- am I being a bee f***er ? (sorry, french literal translation for 'being too finicky')

Thanks

GazL 08-19-2012 04:59 AM

Quote:

Originally Posted by zithro (Post 4757931)
I have two questions:
- shouldn't the brackets be removed from the command in rc.wireless ? Even going further, shouldn't the command be tr abcdef ABCDEF ?
- why is this command interpreted differently at boot time and in bash ?
- am I being a bee f****r ? (sorry, french literal translation for 'being too finicky')

That's 3 questions... but

Yes, they should.

I'm not sure (but the [ and ] will be treated as literals which explains why it still looks like it works when you run it manually),

And no you're not, though use of the f word is undesirable here on LQ.


As it happens, the tr can be avoided completely as sed can be asked to do the upper-case conversion by adding a "\U"
Code:

/sbin/ifconfig ${INTERFACE} | sed -ne 's/.*\(..:..:..:..:..:..\).*/\U\1/p'

P.S. Good spot though.

zithro 08-19-2012 07:03 AM

Yeah 3 questions, but the 3rd was more rhetorical. Starred the f word though ;)

Ok for the difference between boot/bash. Can commands inputs/outputs be interpreted differently depending on the shell one's using ?
And btw, what's the shell used at boot time, sh ? Or it's not really a shell ?

Thanks for your answers, and the sed switch, gonna edit my file.
Maybe slack14 will incorporate your changes.

GazL 08-19-2012 07:59 AM

The shell being used should be bash, but invoked as /bin/sh which does change some of it's behaviour. But even so, I don't understand what was upsetting tr on your system as the error should have been harmless. Most odd.

zithro 08-19-2012 09:19 AM

Ok, i created a test user with the /bin/sh shell instead of /bin/bash, and the command is showing the error.
So 'tr' parameters are not interpreted the same way in bash and sh.
Thanks for pointing that out to me !

PS : the error was in fact harmless, as my wireless card was properly working. The HWADDR var is even not needed for my setup, as im not using the rc.wireless.conf file. Can as well comment the line.
I was just trying to understand & suppress the error message (dont like them).

From a newbie perspective, the wpa_supplicant integration is not as clear as the rc.* scripts are.
I wish the whole WPA thing could be configured from ONLY the rc.wireless/rc.wireless.conf files (so without a wpa_supplicant.conf file). From what I read and understood in AlienBOB's WPA guide, it's not possible. But me noob, so maybe I wasn't getting the whole point. Now I messed a bit more with the files, I'm gonna re-read this guide.

But now I think about it, I read in slack14 changelog (search for "rc.wireless" in http://slackware.com/changelog/current.php?cpu=i386 ):
Quote:

Perhaps this was the cause of some of the reports of non-functional wireless interfaces?
My 'tr' error MAY be a cause for non-functional wireless devices.
If you use the rc.wireless.conf file for wireless settings, and you dont write them in the generic case ($HWADDR in *), rather in the card-specific blocks ($HWADDR in xx:xx:xx), as the $HWADDR is not set, the script may not find the correct parameters, as never entering any case ?!
My 2 cents.


All times are GMT -5. The time now is 12:04 AM.