创建一个shell脚本
vim hello_shell.sh
进入vim编辑器,按i进入插入模式
#!bin/zsh
for ((i=0; i<10; i++)); do
echo “hello_shell”
done
exit 0
按Esc退出插入模式,输入:wq退出,再为文件添加可执行权限
chmod 755 hello_shell.sh
这时候就可以运行了
./hello_shell.sh
创建一个c程序
vim hello_word.c
编辑c程序
#include <stdio.h>
int main(void)
{
printf("hello world!!");
return 0;
}
为上述文件创建目录mybin,并移入其中
mkdir mybin
mv hello_shell.sh hello_world.c mybin/使用gcc生成可执行文件
gcc -o hello_world hello_world.c
运行两个程序
转到mybin目录cd mybin
./hello_shell.sh
./hello_world 注意不是hello_world.c可以加path使其在任意目录下都可运行
echo “PATH=$PATH:/home/shiyanlou/mybin” >> .zshrc”
source .zshrc<==>. ./.zshrc
echo是将新的路径追加到.zshrc
source 是使其生效
source 的别名.
加过路径后运行就不需要目录了,直接
hello_shell.sh
hello_word