0

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
Second

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
Second

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

script:

#!/bin/bash

file = $1

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

    echo "First"
else
    echo "Second"

fi
George
  • 535

1 Answers1

5
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

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].