一个最简单的shell程序

Shell脚本与C程序创建
  1. 创建一个shell脚本

    vim hello_shell.sh
    这里写图片描述

  2. 进入vim编辑器,按i进入插入模式

    #!bin/zsh
    for ((i=0; i<10; i++)); do
    echo “hello_shell”
    done
    exit 0
    这里写图片描述

  3. 按Esc退出插入模式,输入:wq退出,再为文件添加可执行权限

    chmod 755 hello_shell.sh
    这里写图片描述
    这时候就可以运行了
    ./hello_shell.sh
    这里写图片描述

  4. 创建一个c程序

    vim hello_word.c

  5. 编辑c程序

 #include <stdio.h>
   int main(void)
  {
    printf("hello world!!");
    return 0;
   }
  1. 为上述文件创建目录mybin,并移入其中

    mkdir mybin
    mv hello_shell.sh hello_world.c mybin/

  2. 使用gcc生成可执行文件

    gcc -o hello_world hello_world.c

  3. 运行两个程序
    转到mybin目录

    cd mybin
    ./hello_shell.sh
    ./hello_world 注意不是hello_world.c

  4. 可以加path使其在任意目录下都可运行

    echo “PATH=$PATH:/home/shiyanlou/mybin” >> .zshrc”
    source .zshrc<==>. ./.zshrc
    echo是将新的路径追加到.zshrc
    source 是使其生效
    source 的别名.
    加过路径后运行就不需要目录了,直接
    hello_shell.sh
    hello_word

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值