linux运维操作--variable

Posted 咸鱼加辣

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux运维操作--variable相关的知识,希望对你有一定的参考价值。

先来看点前景:

再看点儿介绍

This tutorial will help you understand how to create and remove files, copy and rename them, create links to them, etc.
In Unix, there are three basic types of files

1、Ordinary Files

An ordinary file is a file on the system that contains data, text, or program instructions. In this tutorial, you look at working with ordinary files.
2、Directories
Directories store both special and ordinary files. For users familiar with Windows or Mac OS, Unix directories are equivalent to folders.
3、Special Files
Some special files provide access to hardware such as hard drives, CD-ROM drives, modems, and Ethernet adapters. Other special files are similar to aliases or shortcuts and enable you to access a single file using different names.

介绍太多,一篇博客放不下。
接下来瞅瞅运维人员打交道最多的命令行:

Listing Files

$ls
$ls -l

估计接下来的是很有用的,叫Metacharacters

文件还有一个注意点。叫什么Hidden Files


重要的一点儿来了,variables
首先来点儿开胃菜

Just about every programming language in existence has the concept of variables - a symbolic name for a chunk of memory to which we can assign values, read and manipulate its contents.

再贴几个练习的脚本
创建var.sh脚本

#!/bin/sh
MY_MESSAGE="Hello World"
echo $MY_MESSAGE

This assigns the string “Hello World” to the variable MY_MESSAGE then echoes out the value of the variable.

Note that we need the quotes around the string Hello World Whereas we could get away with echo Hello World because echo will take any number of parameters, a variable can only hold one value, so a string with spaces must be quoted so that the shell knows to treat it all as one. Otherwise, the shell will try to execute the command World after assigning MY_MESSAGE=Hello

Scope of Variables

看下来的要点是:要让一个变量生效,第一遵守的是在#!/bin/bash之前的变量范围,都会执行。

有时间再整理几种对文本内容读取的shell commad

参考链接

https://www.shellscript.sh/variables1.html

以上是关于linux运维操作--variable的主要内容,如果未能解决你的问题,请参考以下文章

linux运维必须知道的几个常用命令

Linux都会学到哪些东西?运维呢?

[linux运维] 利用zabbix监控linux高危命令并发送告警

这 10 种 Linux 命令线上操作,运维一定要谨记

一点不懂到小白的linux系统运维经历分享

一点不懂到小白的linux系统运维经历分享