-3

I am currently doing an exercise on bash. Trying to use bzip2 gzip and zip to determine which way is most efficient compressing program. The question is on the zip command part. It works and echo the size of file ziped. However, the linux shows that

line 22: adding:: command not found

enter image description here

AdminBee
  • 22,803
alan
  • 1

2 Answers2

4

The error comes from your use of $():

$(zip "$1.zip" $1)

This is command substitution, which replaces the command with its output. So the shell takes zip’s output and tries to interpret it as part of the shell script:

adding: ...

adding: isn’t a valid command on your system, and the shell complains about it.

You should run the command directly:

zip "$1.zip" "$1"

If you want to get rid of its output, redirect it, or use zip’s -q option (“quiet”):

zip "$1.zip" "$1" > /dev/null
zip -q "$1.zip" "$1"

This will still show any errors that occur.

Stephen Kitt
  • 434,908
0

Make sure you have the zip command installed. I'm on Debian Linux, and zip is not installed by default, even though unzip is installed.

Also, the syntax for the command calling zip is different than the commands calling gzip and bzip2:

"$1.zip" versus "${1}.bz2" and "${1}.gz"
pell
  • 112