1

I have a text file, mac.txt, with one line that looks like this:

4a:38:61:e1:71:7c

... and I have a bash script, mask.sh, that simply changes my MAC address:

#!/bin/bash

sudo ifconfig wlan0 down
sudo macchanger -m 16:dx:0b:rc:4a:32 wlan0
sudo ifconfig wlan0 up

And I'm trying to figure out how to write a bash script that will copy the MAC address from mac.txt and replace it with the MAC address in mask.sh, so that it looks like this:

#!/bin/bash

sudo ifconfig wlan0 down
sudo macchanger -m 4a:38:61:e1:71:7c wlan0
sudo ifconfig wlan0 up

I've tried a couple variations with sed, cut, and paste but am too embarrassed to show what I'd tried. I'm still pretty new to this.

4

1 Answer 1

1

As schrodigerscatcuriosity commented, you could use bash's command substitution:

sudo macchanger -m $(cat mac.txt) wlan0

or, since you're just using cat on a file:

sudo macchanger -m $(< mac.txt) wlan0

These are explained in the bash manual under Command Substitution.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .