如何让linux在当前目录下找到可执行程序

    xiaoxiao2021-03-25  154

    在vi中写完c文件后,使用gcc进行编译,即:gcc xx.c 生成xx.out文件,然后再输入 ./xx.out 再执行。虽然能够完成对c文件的编译,但是较麻烦。使用.bash_profile来完成。

    第一步:

    cd 进入宿主目录下

    第二步:

    vi .bash_profile打开宿主目录名为.bash_profile的文件,若没有此文件则新建它

    第三步:

    在PATH后面加" :. " 代表可以在当前目录下可找到可执行文件

    第四步:

    vi保存退出

    第五步:

    让.bash_profile生效即命令行输入" . .bash_profile"

    以上五步后每个用户都有各自的.bash_profile文件,在用gcc编译c/c++文件后,生成的可执行文件,直接在编译此可执行文件即可。

    .bash_profile文件内容如下:

    # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ];then          . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin:. export PATH

    转载请注明原文地址: https://ju.6miu.com/read-9465.html

    最新回复(0)