Page 1 of 1

command line error with substrings "bad sustitution"

Posted: Sat Mar 16, 2013 8:42 pm
by bull.backup
Hope that you continue believing that there are note supid questions, Iḿ newbie.
linux Mint 14 mate, 32 bits, installed on a pendrive.

I am trying to get the mac address fron ifconfig comand.
command--> mac=${(ifconfig wlan0 |grep HWaddr):38:19}
linux --> bash: ${(ifconfig wlan0 |grep HWaddr):38:19}: bad substitution

if I do it in two steps it works fine.
mint@mint ~ $ a=$(ifconfig wlan0 |grep HWaddr)
mint@mint ~ $ b=${a:38:19}
mint@mint ~ $ echo $b
xx.xx.xx.xx.xx.xx

I am sure that this question is a bit stupid, at least. But I can not find where the problem. I tested whit little variations and the problem is the same.
any help will be apreciated.
Jose

Re: command line error with substrings "bad sustitution"

Posted: Sun Mar 17, 2013 7:00 am
by xenopeek
I can't remember all the bash syntax, so would just use sed to cut off the part of the line that you don't want. Result is the mac address.

Code: Select all

mac=$(ifconfig eth0 | grep HWaddr | sed 's/.*HWaddr //')
Moved your topic here as perhaps the scripting wizards here will have an answer how to do this with the bash syntax :wink:

Re: command line error with substrings "bad sustitution"

Posted: Sun Mar 17, 2013 6:52 pm
by bull.backup
thanks a lot xenopeek,
this solves my problem, I did not tried to use sed because I ignore how to work with it.
I still ignore why the bash fails, but your solution is very nice! hopefully, someone will explain why the bash command is failing

thanks again.