Why do you need ./ (dot-slash) before executable or script name to run it in bash?

前端 未结 9 920
耶瑟儿~
耶瑟儿~ 2020-11-22 03:59

When running scripts in bash, I have to write ./ in the beginning:

$ ./manage.py syncdb

If I don\'t, I get an error message:

9条回答
  •  礼貌的吻别
    2020-11-22 04:47

    All has great answer on the question, and yes this is only applicable when running it on the current directory not unless you include the absolute path. See my samples below.

    Also, the (dot-slash) made sense to me when I've the command on the child folder tmp2 (/tmp/tmp2) and it uses (double dot-slash).

    SAMPLE:

    [fifiip-172-31-17-12 tmp]$ ./StackO.sh
    
    Hello Stack Overflow
    
    [fifi@ip-172-31-17-12 tmp]$ /tmp/StackO.sh
    
    Hello Stack Overflow
    
    [fifi@ip-172-31-17-12 tmp]$ mkdir tmp2
    
    [fifi@ip-172-31-17-12 tmp]$ cd tmp2/
    
    [fifi@ip-172-31-17-12 tmp2]$ ../StackO.sh
    
    Hello Stack Overflow
    

提交回复
热议问题