0

In the following script I'm coping lshw output to the file and then checking in file match for sn number. If I want to check additional numbers, what the better way to do so?

#!/bin/sh
lshw > lshw.txt
sn=123456
if grep -q $sn lshw.txt; then
    echo "Match"
else
    echo "Doesn't exist"
fi
shebang
  • 11
  • 2
  • 2
    The given code has several errors. Use [Shellcheck](https://www.shellcheck.net/) to find them. – pjh May 28 '22 at 18:49
  • 2
    The program has an `sh` shebang line but it's tagged `bash`. See [Difference between sh and Bash](https://stackoverflow.com/q/5725296/4154375). – pjh May 28 '22 at 18:53
  • 1
    What do you mean by "check additional numbers"? – pjh May 28 '22 at 18:55
  • 1
    See the "Before asking about problematic code" and "How to turn a bad script into a good question" sections of the ['bash' tag wiki - Stack Overflow](https://stackoverflow.com/tags/bash/info). – pjh May 28 '22 at 18:55
  • @pjh Thanks. Regarding additional numbers, I meant additional hw parts. – shebang May 30 '22 at 10:41
  • Does `for sn in 123456 112358 246135; do if grep -q "$sn" lshw.txt; then echo "'$sn' match"; else echo "'$sn' doesn't exist"; fi; done` do what you want? If not, why not? – pjh May 30 '22 at 12:32

0 Answers0