Shell Script

Trying to figure out the command to read a file that contains the paths to six files, then compresses those files

Any attempts/ideas/thoughts from your side?

1 Like

I know how to compress the files with the tar command, but I'm unsure if using the while read do string of commands will work.
Here is what I have so far:

Echo "Creating compressed file from file1"
While read file1
Do
Echo "Contents of file are:"
Cat file1
Tar -zcvf file1.tgz
Echo "The size of file1.tar.gz is:"

(Need command to display size and file name of compressed file)

Please use code tags as required by forum rules!

There are quite some syntactical errors and inconsistencies in your snippet.

  • All the commands NEED to be lower case.
  • The while loop is missing the done < srcfile .
  • The file1 variable is not expanded ( $ sign missing)
  • tar doesn't have a path to be tar red.
  • There's two different extensions of the tar file.

ls -l will display the required values.

Sorry, iPad auto capitalizes. Didn't add the done at the end, but not sure if I need to use the while do done commands for this. When I run the command like it is above it stops after the first echo.

The redirected while ... do ... done will do exactly what you want.

Ok here is what I have:

echo "Creating Compressed File from file1"
while read file1; do
echo "Contents of file are:"
cat file1
tar -zcvf file1.tgz
echo "The size of file1.tgz is:"
stat file1.tgz
done

But when I run it, it just stops after the first

echo

---------- Post updated at 10:24 AM ---------- Previous update was at 10:22 AM ----------

Obviously I need a tutorial on how to use the code button

Did you read the post#4 ti its entirety (and heed it)?

Where do I find post#4?

---------- Post updated at 11:59 AM ---------- Previous update was at 10:31 AM ----------

Re-posted this in the correct forum, sorry.

This misfiled homework item thread is closed.