Shell script not running, command not found

后端 未结 12 1797
天涯浪人
天涯浪人 2020-12-03 04:37

I am very, very new to UNIX programming (running on MacOSX Mountain Lion via Terminal). I\'ve been learning the basics from a bioinformatics and molecular methods course (we

相关标签:
12条回答
  • 2020-12-03 05:16

    Try chmod u+x MigrateNshell.sh

    0 讨论(0)
  • 2020-12-03 05:17

    For security reasons, the shell will not search the current directory (by default) for an executable. You have to be specific, and tell bash that your script is in the current directory (.):

    $ ./MigrateNshell.sh
    
    0 讨论(0)
  • 2020-12-03 05:18

    There have been a few good comments about adding the shebang line to the beginning of the script. I'd like to add a recommendation to use the env command as well, for additional portability.

    While #!/bin/bash may be the correct location on your system, that's not universal. Additionally, that may not be the user's preferred bash. #!/usr/bin/env bash will select the first bash found in the path.

    0 讨论(0)
  • 2020-12-03 05:22

    Add below lines in your .profile path

    PATH=$PATH:$HOME/bin:$Dir_where_script_exists
    
    export PATH
    

    Now your script should work without ./

    Raj Dagla

    0 讨论(0)
  • 2020-12-03 05:23

    I'm new to shell scripting too, but I had this same issue. Make sure at the end of your script you have a blank line. Otherwise it won't work.

    0 讨论(0)
  • 2020-12-03 05:26

    Change the first line to the following as pointed out by Marc B

    #!/bin/bash 
    

    Then mark the script as executable and execute it from the command line

    chmod +x MigrateNshell.sh
    ./MigrateNshell.sh
    

    or simply execute bash from the command line passing in your script as a parameter

    /bin/bash MigrateNshell.sh
    
    0 讨论(0)
提交回复
热议问题