I tried to create a script from this sentence as follows:
#!/bin/bash if [ $# -eq 0 ]; then tail -f /var/log/mylog.log fi if [ $# -eq 1 ]; then tail -f /var/log/mylog.log | perl -pe 's/.*$1.*/\e[1;31m$&\e[0m/g' fi
It shows the black tail of the file when I do not pass the arguments to the script, but each line is red when I pass the argument. I would like it to color only lines containing the word passed into the script.
For example, these will be colored lines containing the word βinformationβ:
./color_lines.sh info
How to change a script to work with one argument?
source share