Bash超级会 - 3.变量啊

2020-12-21  本文已影响0人  etfolin

有变量那就有意思了!就象数学里的xyz。(没有代数的话数学真是太难了,但听说有代数之前,数学的算法更巧妙。)
电脑里的变量命名一般不是xyz,而是会用更有意义的词,这样程序才好看的懂。

#!/bin/bash

:'
下面两个是变量
赋值的时候不加$
调用时加$
'
website=www.fosslinux.com
year=2020

# 环境变量 $USER
name=$USER

echo "为什么不去自己的网站写这个 $website"
echo -e "不是地方啊 $name \n"
echo -e " $year 那你的网站是“什么地方” ?\n"
echo "没人去的地方 $HOSTNAME"

env | less 可以查看所有的环境变量。less是个比more还要强大的命令,明白了吗?

变量 不解释
$# number of command line parameters that were passed to the script.
$@ All the parameters sent to the script.
$? The end status of the last process to execute.
$$ The Process ID of the current script.
$USER The user executing the script.
$HOSTNAME The hostname of the machine executing the script.
$SECONDS The number of seconds the script has been running for.
$RANDOM Returns a random number.
$LINENO Returns the current line number of the script.
上一篇 下一篇

猜你喜欢

热点阅读