无法打开文件作为第一个参数

Geo*_*rge 0 scripting shell-script

我正在尝试运行一个脚本,如:

./script.sh file

但我收到(如果我使用 txt 文件):

=:        cannot open `=' (No such file or directory)
test.txt: ASCII text
Second
Run Code Online (Sandbox Code Playgroud)

如果我使用 gz 文件:

=:           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
Run Code Online (Sandbox Code Playgroud)

(我有脚本和文件在同一目录中)

脚本:

#!/bin/bash

file = $1

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

    echo "First"
else
    echo "Second"

fi
Run Code Online (Sandbox Code Playgroud)

Sté*_*las 5

file = $1
Run Code Online (Sandbox Code Playgroud)

运行file命令=以第一个参数,将 split+glob 运算符的结果应用于脚本的第一个参数作为其余参数。

类似 Bourne 的 shell(如bash, ksh, zsh, ash/ dash, yash)中的变量赋值在符号周围没有空格=

file=$1
Run Code Online (Sandbox Code Playgroud)

file = $1将作为rc,esakangashell 中的赋值有效。cshtcsh有另一种语法:set file = $1:qfish使用set file $argv[1].