Answer the question
In order to leave comments, you need to log in
Why doesn't this bash construct work?
I'm trying to figure out why this bash script doesn't work:
#!/bin/bash
FILE=$1
while read line; do
echo "MAC : $line"
PID=$(ps aux | grep "$line" | grep -v "grep" | awk {'print $2'})
echo "PID : $PID"
done < $FILE
Answer the question
In order to leave comments, you need to log in
I redid the script, probably it was the line break character (the file was made in Windows):
Now everything works like this:
#!/bin/bash
FILE=$1
while read line; do
echo "MAC : $line"
MAC=$(echo "$line" | cut -c 1-17)
PID=$(ps aux | grep $MAC | grep -v "grep" | awk {'print $2'})
echo "PID : $PID"
done < $FILE
./script /путь/до/файла/файл
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question