How can I display only the package names while being unpacked

Asked

Viewed 83 times

0

The question that perhaps already have some answer, however I did not find.

I’m kind of lost, I would say that a little confused even because what I’m asking I think I’ve done it in some circumstance of life but I’m not getting it reminds me exactly 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 command echo followed by your parameter -e indicates that one must display the name(word) one after the other being on the same line. Having as a brief spacing between each package name. This space is defined by the operator \t

To command tar I reserved myself not to make the argument -z, not to leak the flow at the time of extraction.

Good, anyway! What I want, is to show only each package(s) name(s) every instant that, the command tar finishes extracting a package and, move to the next and so on until the cycle ends.

So stay that way, the loop go through the directory /tmp where the packages are situated *.tgz, and should set the name of the first package on the screen and in continuity the heavy work is on account of tar which in turn uncompromises to the system the first package, and the loop goes through the directory /tmp and again arrow the second name of the second package and passes the control to the tar perform its task, and so on ... until the cycle set in the loop.

Being the whole installed(s) at the moment giving thus, an estimate so that the user has patience because the system was in charge of self-installing the TARBALL housed in the folder.

  • if I understand correctly, you have to use the command tar -xf $N so it ripped the content without showing which files are being extracted.

  • @Brumazzidb Oops! I made an ugly mistake, z that gives the flow print when extracting, confuses me with the v. But anyway Brumazzidb. Note that I need to highlight the name without the package extension, hide the data stream while the tar does its job, and finishing the first extract, goes to the second package displays its name just in front of the first package, passes the control to the tar perform and finish the second extraction, now displays the third name of the package in front of the second and starts the extraction, and goes to the fourth etc.

  • I think I understand if the package is called firefox.tar you want me to write firefox, correct?

  • @Brumazzidb Yes! This is your correct assumption. Note that it should first display the name of the package in question in which it will be unpacked, giving a certain amount of time to each other in order to show the name of the next package to be unpacked, and then proceed to the next one. What I want is similar to a Progress-bar, visualizing the name of the file by which the data is being extracted at that moment, and so to do with all, as it is being extracted, the name of the package is also being displayed.

3 answers

1


In Shellscript there are native instructions for handling the String, removes a string from the end of String is one of them, and for that we use the instruction %.

Your use must be inside the key just after the testo you want to cut the sequence.

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

In your code just put after 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, one can create an instruction to assist 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

0

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

0

Put here also what I have done, serving only for future consultation.

#!/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 in the answer(s) was the symbol %, which if applied before any extension and/or word put between the keys ${..}, This cancels what comes after the symbol %, being viewed only what interests us.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.