linux+ln+无效+参数,Linux下执行自定义的可执行命令无效原因

1 前言

用golang编译成可执行文件tt stats text.txt(tt 是编译后重命名的可执行文件),然后直接执行失败了,后来使用./tt stats text.txt可以了。

执行结果如下:

fanbi@ubuntu:~/Work/Go-Work/src/test/cmd$ tt stats text.txt

Command 'tt' not found, but can be installed with:

sudo apt install treetop

fanbi@ubuntu:~/Work/Go-Work/src/test/cmd$ ./tt stats text.txt

The file stat information is:

&{text.txt 218 502 {709183000 63689244046 0x53d060} {2049 283761 1 33270 1000 1000 0 0 218 4096 8 {1553668976 396797000} {1553647246 709183000} {1553668976 396797057} [0 0 0]}}

fanbi@ubuntu:~/Work/Go-Work/src/test/cmd$

仅作为记录使用。

2 样例

文件cc内容如下:

ls -al

//并且执行chmod 777 cc(不需要执行,默认就有执行权限)

执行结果如下:

fanbi@ubuntu:~/Work/Go-Work/src/test/cmd/testDir$ ll

total 12

drwxrwxr-x 2 fanbi fanbi 4096 Mar 27 04:38 ./

drwxrwxrwx 4 fanbi fanbi 4096 Mar 27 04:38 ../

-rwxrwxrwx 1 fanbi fanbi 7 Mar 27 04:29 cc*

fanbi@ubuntu:~/Work/Go-Work/src/test/cmd/testDir$ cc

cc: fatal error: no input files

compilation terminated.

fanbi@ubuntu:~/Work/Go-Work/src/test/cmd/testDir$ ./cc

total 12

drwxrwxr-x 2 fanbi fanbi 4096 Mar 27 04:38 .

drwxrwxrwx 4 fanbi fanbi 4096 Mar 27 04:38 ..

-rwxrwxrwx 1 fanbi fanbi 7 Mar 27 04:29 cc

fanbi@ubuntu:~/Work/Go-Work/src/test/cmd/testDir$

说明:执行cc是没执行,输入./cc 就可以执行。原因是cc会被当成命令来执行,然后没有带参数,即输出致命错误(fatal error)。

运行 Shell 脚本有两种方法:

1、作为可执行程序

将上面的代码保存为 test.sh,并 cd 到相应目录:

chmod +x ./test.sh #使脚本具有执行权限

./test.sh #执行脚本

注意,一定要写成 ./test.sh,而不是 test.sh,运行其它二进制的程序也一样,直接写 test.sh,linux 系统会去 PATH 里寻找有没有叫 test.sh 的,而只有 /bin, /sbin, /usr/bin,/usr/sbin 等在 PATH 里,你的当前目录通常不在 PATH 里,所以写成 test.sh 是会找不到命令的,要用 ./test.sh 告诉系统说,就在当前目录找。

2、作为解释器参数

这种运行方式是,直接运行解释器,其参数就是 shell 脚本的文件名,如:

/bin/sh test.sh

/bin/php test.php

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值