bash 脚本编程基础及配置文件

Shell脚本编程:
编程语言的分类:根据运行方式
编译运行:源代码—>编译器(编译)-- > 程序文件

C语言: 
            解释运行:源代码—>运行时启动解释器,由解释器边解释边运行; 

根据器编程过程中功能的实现是调用库函数调用外部的程序文件;

                    shell脚本编程: 
                                利用系统上的命令及编程组件进行编程; 

             完整编程: 
                            利用库或飙车组件进行编程; 

        编程模型:过程式编程语言,面向对象的编程语言; 

         程序=指令+数据 

                 过程式:以指令为中心来组织代码,数据是服务于代码; 
                     顺序执行,现在执行,循环执行 

             对象式:以数据为中心来组织代码,围绕数据来组织于代码; 
                    类   实例化对象 

shell脚本编程:过程式编程,解释运行,依赖于外部程序文件运行;
如何写 shell脚本:
脚本文件的第一行,顶格:给出 shebang,解释器路径,用于指明解释执行
当前脚本的解释器程序文件

常见的解释器:
#!/bin/bash
#!/usr/bin/python
#!/usr/bin/perl


    第一个脚本: 

~]# cat myfirst.sh

#!/bin/bash useradd user3 echo "user3" | passwd --stdin user3

mktemp -d /tmp/test.XXXX

运行结果:
~]# bash myfirst.sh
uid=1019(user3) gid=1019(user3) 组=1019(user3)
更改用户 user3 的密码 。
passwd:所有的身份验证令牌已经成功更新。
/tmp/test.woDX

脚本:  
        export JAVA_HOME=/usr ~]# nano /etc/profile.d/java.sh 

        重读配置变量文件 
        ~]# . /etc/profile.d/java.sh 

        ~]# export declare -x JAVA_HOME="/usr" 

第二个脚本:

            ~]# cat test.sh 
                            #!/bin/bash 
                            echo "show some under /etc" ls -d /etc/[pP]* echo echo "Traslate lower to upper" 

                            ls -d /var/* | tr 'a-z' 'A-Z' echo echo "create a temp file" 

                            mktemp /tmp/myfile.XXXX 

            ~]# bash test.sh  
                            show some under /etc 
                            /etc/pam.d    
                            /etc/pnm2ppa.conf  
                            /etc/postfix  
                            /etc/printcap 
                            /etc/protocols 
                            /etc/passwd   
                        create a temp file /tmp/myfile.xF5M 

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...