0
#!/bin/bash

file_name = $1
ext = (file -b --mime-type $file_name | sed 's/application\///g')
echo $file_name $ext

Following error messages are seen while executing the code:

file_extractor.sh: line 3: file_name: command not found

file_extractor.sh: line 4: ext: command not found

I have tried adding quotes to the variable, file_name = "$1" didn't work, then substituting $(file -b --mime-type $file_name | sed 's/application\///g'), using double quotes.

Nothing worked.

jww
  • 97,681
  • 90
  • 411
  • 885
Bharath B
  • 3
  • 2
  • 4
    Please take a look: http://www.shellcheck.net/ – Cyrus Jul 01 '18 at 12:19
  • 1
    Possible duplicate of [Command not found error in Bash variable assignment](https://stackoverflow.com/q/2268104/608639). – jww Jul 01 '18 at 13:33
  • Have you ever looked at a working shell script? Please don't try to learn a language by simply *guessing* at what you believe to be the correct syntax. – chepner Jul 01 '18 at 14:16

1 Answers1

0

You have two problems in that script:

  • Assignment to a variable does not allow for spaces around =

    var="val"  # OK
    var = "val"  # Not OK
    
  • You are almost cetainly lookging for command substitution:

    var=$(something that produces output)
    

    Even though that is not the source of your errors. The former one is.

Ondrej K.
  • 8,841
  • 11
  • 24
  • 39