Getting “command not found” error in bash script

前端 未结 6 1208
鱼传尺愫
鱼传尺愫 2020-12-02 00:27

I have written a bash script that gets three paths based on input parameters and then then gets the imagename/filename in the path.

Something like:
I provide:

6条回答
  •  感情败类
    2020-12-02 01:07

    I had this problem, turns out editing a bash script using Notepad++ was adding DOS line endings instead of UNIX line endings. Running the script in a Linux environment was causing the 'command not found' error to be thrown.

    Managed to diagnose the problem by running my script like so:

    bash -x testscript.sh
    

    Which will dump any compiler output. The error message that gets thrown is:

    bash -x testscript.sh
    + $'\r'
    : command not found 2:
    'estscript.sh: line 3: syntax error near unexpected token `{
    

    I fixed the issue by changing the formatting of line endings in Notepad++ to be UNIX not DOS by going Edit -> EOL Conversion -> UNIX.

提交回复
热议问题