Score:0

Reading file from Unzipped Folder - Linux

ck flag

what i'm trying to do is reading files from 4 different Unzipped folders until now with no success, i wrote that script:

for file; do
local file_type=$( file -i "$file" )

case "$file_type" in
    *application/x-bzip2*)    echo "bzip2 file found";;
*application/gzip*)       echo "gzip file found";;
*application/zip*)        echo "zip file found";;
*application/x-xz*)       echo "xz file found";;
*application/x-compress*) echo "compressed file found";;
?)                        echo "${file} cannot be extarcted";;


esac

done

there is no Error, but also there is no output when i'm running it.

cocomac avatar
cn flag
Why do you need to identify the different types of compression? It appears you may have [an XY Problem](https://meta.stackexchange.com/q/66377). If you just need to extract them, do `tar xf filename`, and `tar` is smart enough to automatically determine the format and extract it properly, without you having to tell it what the format of the file is.
hr flag
How exactly are you running it? `for file; do` loops over a script's *positional parameters* - are you actually supplying any?
Hagai Buachi avatar
ck flag
@cocomac i need to given a list of filenames (gunzip, bunzip2, unzip, uncompress) the tar xf filename also not doing anything.
Hagai Buachi avatar
ck flag
@steeldriver can you explain this please?
cocomac avatar
cn flag
`tar xf filename` should certainly do something. Try running `tar xf filename` manually in a terminal, and see if it works. If not, then your `tar` is broken, and you should fix it. If it works there, then something is wrong with your script, perhaps what @steeldriver said. Also, run your script through [ShellCheck](https://www.shellcheck.net/). It will find any errors or mistakes that you missed.
Hagai Buachi avatar
ck flag
@cocomac i ran it in ShellCheck and nothing's wrong, like i said above the tar also not responsing
hr flag
@HagaiBuachi if you ran **exactly what you posted** in shellcheck it should have told you that (1) it has no "shebang" to identify the shell and (2) that `local` is only valid in a function
Hagai Buachi avatar
ck flag
@steeldriver so what should i do to fix it?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.