大数据全系列 教程
1869个小节阅读:464.9k
目录
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
##4.4 特殊变量
$#:位置参数个数
$*:参数列表,双引号引用为一个字符串 ./otherVar.sh a b c d e #"a b c d e"
$@:参数列表,双引号引用为单独的字符串 "a" "b" "c" "d" "e"
$?:上一个命令的退出状态
案例实战:
xxxxxxxxxx
[root@node1 ch4]# vim otherVar.sh
#!/bin/bash
echo "位置参数的个数:$#"
echo "位置参数*的参数列表:$*"
echo "位置参数@的参数列表:$@"
echo "上一个命令执行的结果状态:$?"
[root@node1 ch4]# chmod +x otherVar.sh
[root@node1 ch4]# ./otherVar.sh 1 2 3 a b c d e
位置参数的个数:8
位置参数*的参数列表:1 2 3 a b c d e
位置参数@的参数列表:1 2 3 a b c d e
上一个命令执行的结果状态:0
[root@node1 ch4]# mkdir adir/bdir
mkdir: 无法创建目录"adir/bdir": 没有那个文件或目录
[root@node1 ch4]# echo $?
1
[root@node1 ch4]# [ -d mydir ]
[root@node1 ch4]# echo $?
1
[root@node1 ch4]# [ -d /root ]
[root@node1 ch4]# echo $?
0
[root@node1 ch4]# [ -d mydir ] && echo "mydir is dir"
[root@node1 ch4]# [ -d /root ] && echo "/root is dir"
/root is dir