command line error with substrings "bad sustitution"

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
bull.backup

command line error with substrings "bad sustitution"

Post 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
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
xenopeek
Level 25
Level 25
Posts: 29607
Joined: Wed Jul 06, 2011 3:58 am

Re: command line error with substrings "bad sustitution"

Post 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:
Image
bull.backup

Re: command line error with substrings "bad sustitution"

Post 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.
Locked

Return to “Scripts & Bash”