how to write shell scripts

shell scripts

environment

Login shells read one or more startup files as shown below:

FileContent
/etc/profileA global configuration script that applies to all usres
~/.bash_profileA user’s personal startup file. Can be used to extend or override settings in the global configuration script.
~/.bash_loginIf ~/.bash_profile is not found, bash attempts to read this script.
~/.profileIf neither ~/.bash_profile nor ~/.bash_login is found, bash attempts to read this file. This is the default in Debian-based distributions, such as Ubuntu.

Non-login shell sessions read the following startup files:

FileContent
/etc/bash.bashrcA global configuration script that applies to all users.
~/.bashrcA user’s personal startup file. Can be used to extend or override settings in the global configuration script.

In addition to reading the startup files above, non-login shells also inherit the environment from their parent process, usually a login shell.

Variables

#!/bin/bash

title="This is a  title"

cat <<- EOF
        <html>
        <head>
            <title>
            $title
            </title>
        </head>
        <body>
        $title
        </body>
        </html>
EOF
How To Create A Variable

To create a variable, put a line in your script that contains the name of the variable followed immediately by an equal sign (“=”). No spaces are allowed. After the equal sign, assign the information you wish to store.

Shell Functions

Flow Control

test
ExpressionDescription
-d fileTrue if file is a directory
-e fileTrue if file exists
-f fileTrue if file exists and is a regular file
-L fileTrue if file is a symbolic link
-r fileTrue if file readable by you.
-w fileTrue if file writable by you.
-x fileTrue if file executable by you.
file1 -nt file2True if file1 is newer than(according to the modification)
file1 -ot file2True if ……..older ….
-z stringTrue if string is empty
-n stringTrue if string is not empty
str1 = str2True if str1 equals str2
str1 != str2………..not equal …
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值