Что делает `LOGFILE = $ {1: - / var / log / syslog}`?

Я наткнулся на этот сценарий , содержащий:

LOGFILE=${1:-/var/log/syslog}

Что делает эта строка?

5
задан 19 May 2019 в 23:05

1 ответ

Команда: LOGFILE=${1:-/var/log/syslog} сокращение от:

if [[ "$1" == "" ]]               # if parameter 1 is blank
then
    LOGFILE="/var/log/syslog"     # LOGFILE set to /var/log/syslog
else
    LOGFILE="$1"                  # LOGFILE set to parameter 1
fi

Если параметр 1 не передается, Вы видите:

yad-logfile 1.png

Если Вы передаете paraemeter 1:

journalctl -b > /tmp/messages
yad-logfile /tmp/messages

Вы видите:

yad-logfile 2.png


Исходный рассматриваемый код связывается, был изменен:

#!/bin/bash

# NAME: yad-logfile
# DATE: May 19, 2019.

# From: https://sourceforge.net/p/yad-dialog/wiki/LogViewer/

# This script demonstrates new features of list dialog. Script displays content
# of specified log file and mark some special strings: with word "kernel" by
# setting italic font, with word "error" by light yellow background and with
# word "warn" by pink background 

LOGFILE=${1:-/var/log/syslog}

 PARSER='{font=""; color="#FFFFFF"}; \
/CRON/   {font="italic"}; \
/smartd/ {color="#FFF4B8"}; \
/upower/ {color="#FFD0D8"}; \
OFS="\n" {print $1 " " $2, $3, $4, substr($5,0,index($5,":")-1), \
substr($0,index($0,$6)), font, color; fflush()}'

cat $LOGFILE | awk "$PARSER" | \
yad --title="Log viewer" --window-icon=logviewer \
    --button=gtk-close --geometry 600x350 \
    --list --text="Content of $LOGFILE" \
    --column Date --column Time --column Host \
    --column Tag --column Message:TIP \
    --column @font@ --column @back@

exit $?
6
ответ дан 19 May 2019 в 23:05

Другие вопросы по тегам:

Похожие вопросы: