Shell脚本:Linux Shell脚本学习指南(超详细)

编程开发   © 文章版权由 admin 解释,禁止匿名转载

#楼主# 2021-1-3

你好,欢迎来到「Linux Shell脚本」学习专题,你将享受到免费的 Shell 编程资料,以及很棒的浏览体验。

这套 Shell 脚本学习指南针对初学者编写,它通俗易懂,深入浅出,不仅讲解了基本知识,还深入底层原理,能让你在 1 天时间内快速了解 Shell(当然,要想深入学习还得假以时日)。

Shell 既是一个连接用户和 Linux 内核的程序,又是一门管理 Linux 系统的脚本语言。Shell 脚本虽然没有 C++、Python、Java、C# 等编程语言强大,但也支持了基本的编程元素,这是本教程要重点讲解的。

#【RY】团队欢迎您的加入#

111楼
WD小旺仔 2021-1-5
短格式选项是长格式选项的简写,用一个减号-和一个字母表示,例如ls -l。
112楼
WD小旺仔 2021-1-5
长格式选项是完整的英文单词,用两个减号--和一个单词表示,例如ls --all。
113楼
WD小旺仔 2021-1-5
一般情况下,短格式选项是长格式选项的缩写,也就是一个短格式选项会有对应的长格式选项。当然也有例外,比如 ls 命令的短格式选项-l就没有对应的长格式选项,所以具体的命令选项还需要通过帮助手册来查询。
114楼
WD小旺仔 2021-1-5
使用参数
参数是命令的操作对象,一般情况下,文件、目录、用户和进程等都可以作为参数被命令操作。例如:
115楼
WD小旺仔 2021-1-5
[mozhiyan@localhost demo]$ ls -l main.c
-rw-rw-r--. 1 mozhiyan mozhiyan 650 4月 10 11:06 main.c
116楼
WD小旺仔 2021-1-5
但是为什么一开始 ls 命令可以省略参数?那是因为有默认参数。命令一般都需要加入参数,用于指定命令操作的对象是谁。如果可以省略参数,则一般都有默认参数。例如 ls:
[mozhiyan@localhost ~]$ cd demo
[mozhiyan@localhost demo]$ ls
abc demo.sh a.out demo.txt
getsum main.sh readme.txt a.sh
module.sh log.txt test.sh main.c
117楼
WD小旺仔 2021-1-5
这个 ls 命令后面如果没有指定参数的话,默认参数是当前所在位置,所以会显示当前目录下的文件名。
118楼
WD小旺仔 2021-1-5
选项和参数一起使用
119楼
WD小旺仔 2021-1-5
Shell 命令可以同时附带选项和参数,例如:
[mozhiyan@localhost ~]$ echo "http://c.biancheng.net/shell/' target='_blank'>http://c.biancheng.net/shell/' target='_blank'>http://c.biancheng.net/shell/' target='_blank'>http://c.biancheng.net/shell/' target='_blank'>http://c.biancheng.net/shell/' target='_blank'>http://c.biancheng.net/shell/' target='_blank'>http://c.biancheng.net/shell/' target='_blank'>http://c.biancheng.net/shell/"
http://c.biancheng.net/shell/' target='_blank'>http://c.biancheng.net/shell/' target='_blank'>http://c.biancheng.net/shell/' target='_blank'>http://c.biancheng.net/shell/' target='_blank'>http://c.biancheng.net/shell/' target='_blank'>http://c.biancheng.net/shell/' target='_blank'>http://c.biancheng.net/shell/' target='_blank'>http://c.biancheng.net/shell/
[mozhiyan@localhost ~]$ echo -n "http://c.biancheng.net/shell/' target='_blank'>http://c.biancheng.net/shell/' target='_blank'>http://c.biancheng.net/shell/' target='_blank'>http://c.biancheng.net/shell/' target='_blank'>http://c.biancheng.net/shell/' target='_blank'>http://c.biancheng.net/shell/' target='_blank'>http://c.biancheng.net/shell/' target='_blank'>http://c.biancheng.net/shell/"
http://c.biancheng.net/shell/' target='_blank'>http://c.biancheng.net/shell/' target='_blank'>http://c.biancheng.net/shell/' target='_blank'>http://c.biancheng.net/shell/' target='_blank'>http://c.biancheng.net/shell/' target='_blank'>http://c.biancheng.net/shell/' target='_blank'>http://c.biancheng.net/shell/' target='_blank'>http://c.biancheng.net/shell/[mozhiyan@localhost ~]$
120楼
WD小旺仔 2021-1-5
-n是 echo 命令的选项,"http://c.biancheng.net/shell/"是 echo 命令的参数,它们被同时用于 echo 命令。

评论

登录后才可发表内容
  • 主题

    10

  • 帖子

    2187

  • 关注者

    0

Copyright © 2019 凯特网.   Powered by HYBBS 2.3.4  

Runtime:0.0543s Mem:2150Kb