I'm new to bash and I'm working on script that traverses the tar.gz file archive and in each file changes a string specified to an another string. Args of script: name of archive, searched string, target word.My problem is that when archive name contains a space (e.g. I run script with following args: > change_strings.sh /tmp/tmp.m7xYn5EQ2y/work/data txt a A) I have following error: on line if [ ! -f $filename ] ; then  [: data: binary operator expected, dirname: extra operand `txt'. Here is my code:  #!/bin/bash   filename=${1##*/}  VAR=$1  DIR=$(dirname ${VAR})  cd $DIRif [ ! -f $filename ] ; thenecho no such archive >&2exit 1fiif ! tar tf $filename &> /dev/null; thenecho this is not .tar.gz archive >&2exit 1fidir=`mktemp -dt 'test.XXXXXX'`tar -xf $filename -C $dir  #extract archive to dircd $dir #go to argument directoryFILES=$dir/*for f in $FILESdosed -i s/$2/$3/g $fdonetar -czf $filename * #create tar gz archive with files in current directorymv -f $filename $cdir/$filename #move archiverm -r $dir #remove tmp directory
Spaces in directory name Bash
bash;filenames