shell 之hello world

以前接触linux的比较少,比较常用的几个命令能够使用,接下来的项目中需要使用Linux,所以最近希望能够增强一点Linux的知识,那么就从hello world开始吧

第一步:了解Linux文件的权限

[root@ibm mwq]# ls -l
总用量 8
drwxr-xr-x. 2 root root 4096  6月 25 17:35 hello
-rwxr--r--. 1 root root   33  6月 25 17:56 hello.awk
-rw-r--r--. 1 root root    0  6月 25 17:35 hello.txt

 以上中对于hello目录,其第一位为d,对于文件,其第一位为-(短横线),短横线表示缺少权限,r为读,w为写,x表示可以进入目录或者可以执行文件。

第二步:了解chmod(change mode)命令,可以改变文件的权限,现在了解一下命令的含义

[root@ibm mwq]# chmod u+x hello.awk 

 使用man chmod可以看到以下信息

写道
The letters rwxXst select file mode bits for the affected users: read (r), write (w), execute (or search for directories) (x), execute/search only if the file is a directory
or already has execute permission for some user (X), set user or group ID on execution (s), restricted deletion flag or sticky bit (t). Instead of one or more of these let-
ters, you can specify exactly one of the letters ugo: the permissions granted to the user who owns the file (u), the permissions granted to other users who are members of the
file’s group (g), and the permissions granted to users that are in neither of the two preceding categories (o).

 该命令可以使文件可执行

第三步:通过vim hello.awk编辑文件

输入以下内容

#!/bin/sh

 echo "hello,world!"

 “#!”称为幻数,“#!/bin/sh”表示通过bin/sh进行文件内容的解释

那么echo则表示,通过回显,在命令行中输出hello,world!

第四步:通过:q退出文件编辑模式后,使用sh hello.awk执行文件

[root@ibm mwq]# sh hello.awk 
hello,world!

 好了,以上简单学习的步骤就结束了。

以后有空闲时间一步步学习。。。。。

猜你喜欢

转载自qing-gee.iteye.com/blog/2085049