How can I display only the names of packages while they are being unzipped

0

The question that may already have some answers, however I did not find.

I'm kind of lost, I'd say that a little bit confusing even because what I'm asking I think I've already done it in some circumstance of life but I can not remember me for sure how. It was something more-or-less like this:

Code

#Auto-installar pacotes TARBALL no sistema Linux
for N in "/tmp/{abiword, gnumeric, inkscape, gimp, firefox}.tgz" 
do 
    echo -e "$N\t" && sudo tar zxf $N -C /; 
done

Quick Explanation

This echo command followed by its -e parameter indicates that the name (word) must be displayed one after the other on the same line. Having as a short spacing between each packet name. This space is defined by the \t

For the command tar I reserved not for the argument -z , not to leak the stream at extraction time.

Well, anyway! What I want is to show only each package name (s) at any instant, that the tar command finishes extracting one package and moving to the next and so on until the cycle ends.

Then this way, loop goes through the /tmp directory where the *.tgz packages are located, and the name of the first package must be set on the screen and continuity of the heavy work is done by tar which in turn decompresses the first packet into the system, and loop re-runs the /tmp directory and then re-directs the second name of the second packet and passes the control to tar perform its task, and so on forward ... until the cycle is set to loop .

Being installed at all in the moment giving an estimate so that the user has patience because the system was in charge of auto-installing TARBALL in the folder.

    
asked by anonymous 12.05.2017 / 20:24

3 answers

1

In ShellScript there are native statements to handle String , remove a string from the end of String is one of them, and for this we use the % statement.

Your use should be in the key right after the test you want to trim the sequence.

$ TEXTO="test.sh"
$ echo "${TEXTO%.sh}"
> test

In your code, just put N :

for N in "/tmp/{abiword, gnumeric, inkscape, gimp, firefox}.tgz" 
do 
    echo -e "${N%.tgz}\t" && sudo tar zxf $N -C /; 
done

Now to separate the extraction, you can create an instruction to help time marking.

#!/bin/bash

BREAK=/tmp/i.lock

function count(){ # função para contar o tempo
    touch /tmp/i.lock
    while [ -f "$BREAK" ]; do
        sleep 0.5
        echo -n "."
    done
}

for N in "/tmp/{abiword, gnumeric, inkscape, gimp, firefox}.tgz"; do
    echo -n "Instalando ${N%.tgz}"
    count & # inicia o contador
    tar zxf $N -C /
    rm -f /tmp/i.lock # encerra o contador
    echo " ok"
    let TEMP=0
    sleep 1
done
    
13.05.2017 / 04:01
0

I also post here what I have done, serving only for future reference.

#!/bin/sh

# Local onde suponho que estejam os pacotes TARBALL
I='/tmp' 

# Listamos com todos formato *.tgz com o comando "ls" 
# Logo recortarmos o nomes com "cut -d '/'" após a barra slash "/" 
# Na qual pegamos apenas a coluna 2 com o parâmetro "-f2"
O='ls -1 $I/*.tgz | cut -d '/' -f2'

# Agora aplicamos o laço "for" para percorrer cada uma das instrução
# Definimos a variável para execução condizente com a pasta e arquivos
for N in $O
do 

# Adentramos pra dentro da pasta "/tmp" no qual vamos descompactar o(s) pacote(s)
    cd $I

# Os demais comandos abaixo fazem seu trabalho de uma barra de progresso
    sleep 0.25
    echo -ne "\r" 
    sleep 0.25 
    echo -ne "\r>" 
    sleep 0.25  
    echo -ne "\r>>"
    sleep 0.25 
    echo -ne "\r>>>"
    sleep 0.25 

# Aliado a Barra de Progresso, temos ${N%.tgz} que nos ilustra o nome do(s) pacote(s) sem o formato final(tgz), por conta do "%" que oculta.
    echo -ne "\r>>>> ${N%.tgz}"

# Realizando a extração pra dentro do filesystem(sistema de arquivos)
    sudo tar zxf "$N" -C /
    echo " ok" 

# Daqui em diante damos um intervalo mínimo para retomada do laço
    sleep 1
done

Well, the fundamental point of the question as well as the answer (s) was the % symbol, which if applied before any extension and / or word placed between the keys ${..} , this voids what comes after the symbol % , and only the one that interests us is displayed.

    
13.05.2017 / 14:43
0

In tar you can use the -v option that is verbose.

    
08.06.2017 / 08:22