AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / ubuntu / Perguntas / 1144591
Accepted
WinEunuuchs2Unix
WinEunuuchs2Unix
Asked: 2019-05-20 12:05:53 +0800 CST2019-05-20 12:05:53 +0800 CST 2019-05-20 12:05:53 +0800 CST

O que `LOGFILE=${1:-/var/log/syslog}` faz?

  • 772

Eu me deparei com este script contendo:

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

O que essa linha faz?

command-line bash
  • 1 1 respostas
  • 496 Views

1 respostas

  • Voted
  1. Best Answer
    WinEunuuchs2Unix
    2019-05-20T12:05:53+08:002019-05-20T12:05:53+08:00

    O comando: LOGFILE=${1:-/var/log/syslog}é uma abreviação de:

    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
    

    Se o parâmetro 1 não for passado, você verá:

    yad-logfile 1.png

    Se passar o parâmetro 1:

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

    você vê:

    yad-logfile 2.png


    O código original no link em questão foi modificado:

    #!/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 $?
    
    • 7

relate perguntas

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    Existe um comando para listar todos os usuários? Também para adicionar, excluir, modificar usuários, no terminal?

    • 9 respostas
  • Marko Smith

    Como excluir um diretório não vazio no Terminal?

    • 4 respostas
  • Marko Smith

    Como descompactar um arquivo zip do Terminal?

    • 9 respostas
  • Marko Smith

    Como instalo um arquivo .deb por meio da linha de comando?

    • 11 respostas
  • Marko Smith

    Como instalo um arquivo .tar.gz (ou .tar.bz2)?

    • 14 respostas
  • Marko Smith

    Como listar todos os pacotes instalados

    • 24 respostas
  • Martin Hope
    Flimm Como posso usar o docker sem sudo? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    led-Zepp Como faço para salvar a saída do terminal em um arquivo? 2014-02-15 11:49:07 +0800 CST
  • Martin Hope
    ubuntu-nerd Como descompactar um arquivo zip do Terminal? 2011-12-11 20:37:54 +0800 CST
  • Martin Hope
    TheXed Como instalo um arquivo .deb por meio da linha de comando? 2011-05-07 09:40:28 +0800 CST
  • Martin Hope
    Ivan Como listar todos os pacotes instalados 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    David Barry Como determino o tamanho total de um diretório (pasta) na linha de comando? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher "Os seguintes pacotes foram retidos:" Por que e como resolvo isso? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford Como os PPAs podem ser removidos? 2010-07-30 01:09:42 +0800 CST

Hot tag

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve