A bash script question
I will pipe compressed archives to the standard input of a bash script.
How can I determine in the same script the name (or rather the extension) of the file that has been piped to the script? My aim is as follows: 1. Pipe compressed files to the script 2. Which should call the appropriate de-compression utility to list the contents (filenames) in the archive 3. It should then return a specific exit code if the archive contained a windows executable |
standard input does not have a filename (unless you pass it as a parameter to the script)
you can try to guess the file type by using the "file" utility (which uses /etc/magic to determine the file type from the file header) |
Well, my script will be specified an external scanner module called by a mail sanitizer in the case of compressed mail attachments.
So far I thought that the mail sanitizer passes the attachments to the standard input of such external scanner modules. Now I rather think it saves the attachments to a temporary location and only passes the filename to the external modules. If it is so, it is better, since I can then obtain the filename in $1, besides, e.g. unzip did not seem very eager to accept data to be uncompressed on its standard input... |
All times are GMT -5. The time now is 06:21 AM. |