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