shell简介

echo $SHELL
/bin/bash
创建第一个shell脚本
touch helloworld.sh
vim helloworld.sh
在helloworld.sh 中输入如下内容:
#!/bin/bash
echo “helloworld”

执行shell文件
- bash/sh +文件的相对路径或者绝对路径
bash hellowrold.sh
hello,world
sh /root/hellowrold.sh
hello,world
- 在脚本的路径前加上“.”或者source
. hellowrold.sh
hello,world
source hellowrold.sh
hello,world
- 采用输入脚本的绝对路径或相对路径执行脚本(必须具有可执行权限+x)
chmod +x hellowrold.sh
ll hellowrold.sh

# 不能直接写hellowrold.sh ,会被当做命令,无法执行。
./hellowrold.sh
hello,world
/root/hellowrold.sh
hello,world
- bash/sh+脚本、、直接脚本的绝对路径或相对路径执行脚本的方式:是在当前shell 中打开一个子shell 来执行脚本内容,当脚本内容结束,则子shell

最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



