# Shell Script

**URL:** <https://community.unix.com/t/shell-script/357048>\
**Category:** Shell Programming and Scripting\
**Created:** [November 28, 2015, 2:08pm UTC](https://community.unix.com/t/shell-script/357048 "2015-11-28T14:08:01Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luvs2drnk](https://community.unix.com/letter_avatar/luvs2drnk/32/6_449c533f586939b6e5f246632a46421f.png) [@Luvs2drnk](https://community.unix.com/u/Luvs2drnk)\
**Post date:** [November 28, 2015, 2:08pm UTC](https://community.unix.com/t/shell-script/357048/1 "2015-11-28T14:08:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/6_449c533f586939b6e5f246632a46421f.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [November 28, 2015, 2:14pm UTC](https://community.unix.com/t/shell-script/357048/2 "2015-11-28T14:14:23Z")

</div>

Any attempts/ideas/thoughts from your side?

---

<div class="post-metadata">

**Author:** ![Luvs2drnk](https://community.unix.com/letter_avatar/luvs2drnk/32/6_449c533f586939b6e5f246632a46421f.png) [@Luvs2drnk](https://community.unix.com/u/Luvs2drnk)\
**Post date:** [November 28, 2015, 2:54pm UTC](https://community.unix.com/t/shell-script/357048/3 "2015-11-28T14:54:25Z")

</div>

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:

```nohighlight
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)

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/6_449c533f586939b6e5f246632a46421f.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [November 28, 2015, 3:05pm UTC](https://community.unix.com/t/shell-script/357048/4 "2015-11-28T15:05:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Luvs2drnk](https://community.unix.com/letter_avatar/luvs2drnk/32/6_449c533f586939b6e5f246632a46421f.png) [@Luvs2drnk](https://community.unix.com/u/Luvs2drnk)\
**Post date:** [November 28, 2015, 3:10pm UTC](https://community.unix.com/t/shell-script/357048/5 "2015-11-28T15:10:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/6_449c533f586939b6e5f246632a46421f.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [November 28, 2015, 3:13pm UTC](https://community.unix.com/t/shell-script/357048/6 "2015-11-28T15:13:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Luvs2drnk](https://community.unix.com/letter_avatar/luvs2drnk/32/6_449c533f586939b6e5f246632a46421f.png) [@Luvs2drnk](https://community.unix.com/u/Luvs2drnk)\
**Post date:** [November 28, 2015, 3:24pm UTC](https://community.unix.com/t/shell-script/357048/7 "2015-11-28T15:24:15Z")

</div>

Ok here is what I have:

```nohighlight
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

```nohighlight
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

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/6_449c533f586939b6e5f246632a46421f.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [November 28, 2015, 3:26pm UTC](https://community.unix.com/t/shell-script/357048/8 "2015-11-28T15:26:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Luvs2drnk](https://community.unix.com/letter_avatar/luvs2drnk/32/6_449c533f586939b6e5f246632a46421f.png) [@Luvs2drnk](https://community.unix.com/u/Luvs2drnk)\
**Post date:** [November 28, 2015, 4:59pm UTC](https://community.unix.com/t/shell-script/357048/9 "2015-11-28T16:59:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Don\_Cragun](https://community.unix.com/user_avatar/community.unix.com/don_cragun/32/2682_2.png) [@Don\_Cragun](https://community.unix.com/u/Don_Cragun)\
**Post date:** [November 28, 2015, 6:46pm UTC](https://community.unix.com/t/shell-script/357048/10 "2015-11-28T18:46:35Z")

</div>

This misfiled homework item thread is closed.
