Hadoop搭建笔记(11)

本文是作者学习Hadoop搭建过程中的笔记,从Linux基础开始,详细介绍了shell的介绍、运行环境和方式,以及如何编写和执行shell脚本,包括变量的使用和字符串操作。适合初学者入门。
摘要由CSDN通过智能技术生成

本文是我学习Hadoop搭建过程中的各种笔记,内容来自于各种公开的教程,起点非常低,从Linux基础开始,直至在PC上搭建Hadoop成功,是真正的从零开始。

感谢过程中帮助我的各位认识的和不认识的老师。

20、shell介绍和变量

1、shell介绍

shell是一个用C语言编写的程序,它被称为用户使用Linux的桥梁。

shell即是一种命令语言,又是一种程序设计语言

shell脚本(shell script),是一种为shell编写的脚本语言

2、shell运行环境和运行方式

2.1 shell编程和Java、Python等一样【都是一种编程语言,语言简单不需太多语法,不需动态编译】。只需要一个文本编辑器和解释工具即可。Linux的shell太多,常见的有:

Bourne Shell(/urs/bin/sh/或/bin/sh)在Linux下: /bin/sh

Bourne Again Shell (/bin/bash)在Linux下: /bin/bash

[root@hadoop01 ~]# which sh

/bin/sh

[root@hadoop01 ~]# which bash

/bin/bash

C Shell (/usr/bin/csh) 在Linux下: /bin/tcsh

[root@hadoop01 ~]# which csh

/bin/csh

[root@hadoop01 ~]# which tcsh

/bin/tcsh

K Shell (/usr/bin/ksh) 是cshell的超集

[root@hadoop01 ~]# which ksh

/usr/bin/which: no ksh in (/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/jdk1.8.0_144//bin::/root/bin)

Shell for Root (/sbin/sh)

其中Linux自带有:/bin/bash、/bin/sh、/bin/tcsh、/bin/csh等。以上集中都是交互式。

bash易用和免费。bash在日常工作中广泛被使用。

bash也是大多数的Linux系统默认的Shell

/bin/sh 等价于 /bin/bash

一个hello world实例: 

编辑第一个文件脚本shell:vi/home/shell/first.sh  

[root@hadoop01 shell]# vi ./firstshell  firstshell:Linux命令的集合,也称之为shell脚本

#!/bin/bash

echo 'hello world'

 

现在shell脚本就编好了:

[root@hadoop01 shell]# ll

total 4

-rw-r--r--. 1 root root 32 Apr 23 17:19 firstshell  

 

运行shell脚本(加可执行的权限或加解释器):

[root@hadoop01 shell]# ll

total 4

-rw-r--r--. 1 root root 32 Apr 23 17:19 firstshell

-rw-r--r--:是没有执行权限的,此时./firstshell是Tab不出来的

 

加可执行权限:

[root@hadoop01 shell]# chmod 744 ./firstshell

[root@hadoop01 shell]# ll

total 4

-rwxr--r--. 1 root root 32 Apr 23 17:19 firstshell

 

此时就能打印出来了:

[root@hadoop01 shell]# ./firstshell

hello world

 

脚本是shell命令的集合,此时在外面,echo也能打印出来:

[root@hadoop01 shell]# echo 'hello world'

hello world

此时:chmod 644

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Demoatnes

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值