目录
- 1.Shell字符串拼接(连接、合并)
- 2.shell产生随机数的方法
- 2.1 通过内部系统变量($RANDOM)
- 2.2 读取linux的uuid码
- 2.3 使用设备文件生成
- 3.修改hostname
1.Shell字符串拼接(连接、合并)
#!/bin/bash
name=\”Shell\”
url=\”http://c.biancheng.net/shell/\”
str1=$name$url #中间不能有空格
str2=\”$name $url\” #如果被双引号包围,那么中间可以有空格
str3=$name\”: \”$url #中间可以出现别的字符串
str4=\”$name: $url\” #这样写也可以
str5=\”${name}Script: ${url}index.html\” #这个时候需要给变量名加上大括号
echo $str1
echo $str2
echo $str3
echo $str4
echo $str5
运行结果:
Shellhttp://c.biancheng.net/shell/Shell http://c.biancheng.net/shell/Shell: http://c.biancheng.net/shell/Shell: http://c.biancheng.net/shell/ShellScript: http://c.biancheng.net/shell/index.html
PS:$name 和 $url 之间之所以不能出现空格,是因为当字符串不被任何一种引号包围时,遇到空格就认为字符串结束了,空格后边的内容会作为其他变量或者命令解析。
2.shell产生随机数的方法
以下是我使用过的:
2.1 通过内部系统变量($RANDOM)
echo $RANDOM
2.2 读取linux的uuid码
uuid=$(cat /proc/sys/kernel/random/uuid| cksum | cut -f1 -d \” \”)
echo $uuid
2.3 使用设备文件生成
可以通过 /dev/random 和 /dev/urandom 提供随机数,建议使用 /dev/urandom提取8位包含字母、数字、下划线的随机数。
[root@localhost ~]# tr -cd \’_a-zA-Z0-9\’ < /dev/urandom | head -c 8
c5VkRl_H[root@localhost ~]#
3.修改hostname
hostname 的作用
- hostname是主机名,用于在系统中标识一台机器。
- 在登陆linux系统后,[root@ubuntu],其中@后面的是主机名字,通过主机名字,可以判断登陆的系统。
修改hostname修改 /etc/hostname文件,修改其中的名称,然后重启设备reboot
到此这篇关于shell脚本配置hostname的方法步骤的文章就介绍到这了,更多相关shell脚本配置hostname内容请搜索悠久资源网以前的文章或继续浏览下面的相关文章希望大家以后多多支持悠久资源网!
您可能感兴趣的文章:
- 基于Python Shell获取hostname和fqdn释疑