I am trying to run a script like :

./script.sh file

but I am receiving ( if I use a txt file ):

=:        cannot open `=' (No such file or directory)
test.txt: ASCII text

If I use a gz file:

=:           cannot open `=' (No such file or directory)
test.txt.gz: gzip compressed data, was "test.txt", last modified: Wed Jul 20 09:17:58 2016, from Unix

( I have the script and the file in the same directory )



file = $1

if [[ $file == *.gz ]];then

    echo "First"
    echo "Second"

  • 2
    @Rahul irrelevant. The problem is spaces around = – 123 Jul 20 '16 at 9:36
file = $1

runs the file command with = as the first argument and the result of the split+glob operator applied to the script's first parameter as the remaining arguments.

Variable assignments in Bourne-like shells (like bash, ksh, zsh, ash/dash, yash) are with no spaces around the = sign:


file = $1 would be valid as an assignment in rc, es or akanga shells. csh and tcsh have yet another syntax: set file = $1:q and fish uses set file $argv[1].

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.