command line error with substrings "bad sustitution"

Forum rules
Before you post please read this

command line error with substrings "bad sustitution"

Postby bull.backup on Sat Mar 16, 2013 8:42 pm

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
bull.backup
Level 1
Level 1
 
Posts: 3
Joined: Sat Mar 16, 2013 7:48 pm

Linux Mint is funded by ads and donations.
 

Re: command line error with substrings "bad sustitution"

Postby xenopeek on Sun Mar 17, 2013 7:00 am

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:
User avatar
xenopeek
Level 21
Level 21
 
Posts: 14889
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: command line error with substrings "bad sustitution"

Postby bull.backup on Sun Mar 17, 2013 6:52 pm

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.
bull.backup
Level 1
Level 1
 
Posts: 3
Joined: Sat Mar 16, 2013 7:48 pm


Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 1 guest