Linux-shell-完全详解(2)

简介:

Linux-shell-完全详解(2)

 Shell简介:什么是Shell,Shell命令的两种执行方式1

 几种常见的Shell1

 Shell脚本语言与编译型语言的差异2

四、什么时候使用Shell3

 第一个Shell脚本3

六、Shell变量:Shell变量的定义、删除变量、只读变量、变量类型5

七、Shell特殊变量:Shell $0, $#, $*, $@, $?, $$和命令行参数6

 Shell替换:Shell变量替换,命令替换,转义字符9

 Shell运算符:Shell算数运算符、关系运算符、布尔运算符、字符串运算符12

 Shell注释20

一、 Shell字符串20

十二、Shell数组:shell数组的定义、数组长度21

三、 Shell echo命令23

四、 shell printf命令:格式化输出语句24

十五、Shell if else语句25

十六、Shell case esac语句28

十七、Shell for循环30

十八、Shell while循环31

十九、Shell until循环32

二十、Shell break和continue命令33

二十一、Shell函数:Shell函数返回值、删除函数、在终端调用函数35

二十二、Shell函数参数37

二十三、Shell输入输出重定向:Shell Here Document,/dev/null文件38

二十四、Shell文件包含41


Linux-shell-完全详解(2)

 

九、Shell运算符:Shell算数运算符、关系运算符、布尔运算符、字符串运算符

 

Bash 支持很多运算符,包括算数运算符、关系运算符、布尔运算符、字符串运算符和文件测试运算符。

原生bash不支持简单的数学运算,但是可以通过其他命令来实现,例如 awk 和 exprexpr 最常用。

expr 是一款表达式计算工具,使用它能完成表达式的求值操作。

例如,两个数相加:

#!/bin/bash

 

val=`expr 2 + 2`

echo "Total value : $val"

运行脚本输出:

Total value : 4

注意:

1、表达式和运算符之间要有空格,例如 2+2 是不对的,必须写成 2 + 2,这与我们熟悉的大多数编程语言不一样。

2、完整的表达式要被 ` ` 包含,注意这个字符不是常用的单引号,在 Esc 键下边。

算术运算符

先来看一个使用算术运算符的例子:

#!/bin/sh

 

a=10

b=20

val=`expr $a + $b`

echo "a + b : $val"

 

val=`expr $a - $b`

echo "a - b : $val"

 

val=`expr $a \* $b`

echo "a * b : $val"

 

val=`expr $b / $a`

echo "b / a : $val"

 

val=`expr $b % $a`

echo "b % a : $val"

 

if [ $a == $b ]

then

   echo "a is equal to b"

fi

 

if [ $a != $b ]

then

   echo "a is not equal to b"

fi

运行结果:

a + b : 30a - b : -10a * b : 200b / a : 2b % a : 0a is not equal to b

注意:

乘号(*)前边必须加反斜杠(\)才能实现乘法运算;

if...then...fi 是条件语句,后续将会讲解。

 

算术运算符列表

运算符

说明

举例

+

加法

`expr $a + $b` 结果为 30。

-

减法

`expr $a - $b` 结果为 10。

*

乘法

`expr $a \* $b` 结果为  200。

/

除法

`expr $b / $a` 结果为 2。

%

取余

`expr $b % $a` 结果为 0。

=

赋值

a=$b 将把变量 b 的值赋给 a。

==

相等。用于比较两个数字,相同则返回 true。

[ $a == $b ] 返回 false。

!=

不相等。用于比较两个数字,不相同则返回 true。

[ $a != $b ] 返回 true。


注意

条件表达式要放在方括号之间,并且要有空格,例如 [$a==$b] 是错误的,必须写成 [ $a == $b ]

关系运算符

关系运算符只支持数字,不支持字符串,除非字符串的值是数字。

先来看一个关系运算符的例子:

#!/bin/sh

 

a=10

b=20

if [ $a -eq $b ]

then

   echo "$a -eq $b : a is equal to b"

else

   echo "$a -eq $b: a is not equal to b"

fi

 

if [ $a -ne $b ]

then

   echo "$a -ne $b: a is not equal to b"

else

   echo "$a -ne $b : a is equal to b"

fi

 

if [ $a -gt $b ]

then

   echo "$a -gt $b: a is greater than b"

else

   echo "$a -gt $b: a is not greater than b"

fi

 

if [ $a -lt $b ]

then

   echo "$a -lt $b: a is less than b"

else

   echo "$a -lt $b: a is not less than b"

fi

 

if [ $a -ge $b ]

then

   echo "$a -ge $b: a is greater or  equal to b"

else

   echo "$a -ge $b: a is not greater or equal to b"

fi

 

if [ $a -le $b ]

then

   echo "$a -le $b: a is less or  equal to b"

else

   echo "$a -le $b: a is not less or equal to b"

fi

运行结果:

10 -eq 20: a is not equal to b10 -ne 20: a is not equal to b10 -gt 20: a is not greater than b10 -lt 20: a is less than b10 -ge 20: a is not greater or equal to b10 -le 20: a is less or  equal to b

 

关系运算符列表

运算符

说明

举例

-eq

检测两个数是否相等,相等返回 true。

[ $a -eq $b ] 返回 true。

-ne

检测两个数是否相等,不相等返回 true。

[ $a -ne $b ] 返回 true。

-gt

检测左边的数是否大于右边的,如果是,则返回 true。

[ $a -gt $b ] 返回 false。

-lt

检测左边的数是否小于右边的,如果是,则返回 true。

[ $a -lt $b ] 返回 true。

-ge

检测左边的数是否大等于右边的,如果是,则返回 true。

[ $a -ge $b ] 返回 false。

-le

检测左边的数是否小于等于右边的,如果是,则返回 true。

[ $a -le $b ] 返回 true。

布尔运算符

先来看一个布尔运算符的例子:

#!/bin/sh

 

a=10

b=20

 

if [ $a != $b ]

then

   echo "$a != $b : a is not equal to b"

else

   echo "$a != $b: a is equal to b"

fi

 

if [ $a -lt 100 -a $b -gt 15 ]

then

   echo "$a -lt 100 -a $b -gt 15 : returns true"

else

   echo "$a -lt 100 -a $b -gt 15 : returns false"

fi

 

if [ $a -lt 100 -o $b -gt 100 ]

then

   echo "$a -lt 100 -o $b -gt 100 : returns true"

else

   echo "$a -lt 100 -o $b -gt 100 : returns false"

fi

 

if [ $a -lt 5 -o $b -gt 100 ]

then

   echo "$a -lt 100 -o $b -gt 100 : returns true"

else

   echo "$a -lt 100 -o $b -gt 100 : returns false"

fi

运行结果:

10 != 20 : a is not equal to b10 -lt 100 -a 20 -gt 15 : returns true10 -lt 100 -o 20 -gt 100 : returns true10 -lt 5 -o 20 -gt 100 : returns false

 

布尔运算符列表

运算符

说明

举例

!

非运算,表达式为 true 则返回 false,否则返回 true。

[ ! false ] 返回 true。

-o

或运算,有一个表达式为 true 则返回 true。

[ $a -lt 20 -o $b -gt 100 ] 返回 true。

-a

与运算,两个表达式都为 true 才返回 true。

[ $a -lt 20 -a $b -gt 100 ] 返回 false。

字符串运算符

先来看一个例子:

#!/bin/sh

 

a="abc"

b="efg"

 

if [ $a = $b ]

then

   echo "$a = $b : a is equal to b"

else

   echo "$a = $b: a is not equal to b"

fi

 

if [ $a != $b ]

then

   echo "$a != $b : a is not equal to b"

else

   echo "$a != $b: a is equal to b"

fi

 

if [ -z $a ]

then

   echo "-z $a : string length is zero"

else

   echo "-z $a : string length is not zero"

fi

 

if [ -n $a ]

then

   echo "-n $a : string length is not zero"

else

   echo "-n $a : string length is zero"

fi

 

if [ $a ]

then

   echo "$a : string is not empty"

else

   echo "$a : string is empty"

fi

运行结果:

abc = efg: a is not equal to babc != efg : a is not equal to b-z abc : string length is not zero-n abc : string length is not zeroabc : string is not empty

 

字符串运算符列表

运算符

说明

举例

=

检测两个字符串是否相等,相等返回 true。

[ $a = $b ] 返回 false。

!=

检测两个字符串是否相等,不相等返回 true。

[ $a != $b ] 返回 true。

-z

检测字符串长度是否为0,为0返回 true。

[ -z $a ] 返回 false。

-n

检测字符串长度是否为0,不为0返回 true。

[ -z $a ] 返回 true。

str

检测字符串是否为空,不为空返回 true。

[ $a ] 返回 true。

文件测试运算符

文件测试运算符用于检测 Unix 文件的各种属性。

例如,变量 file 表示文件“/var/www/tutorialspoint/unix/test.sh”,它的大小为100字节,具有 rwx 权限。下面的代码,将检测该文件的各种属性:

#!/bin/sh

 

file="/var/www/tutorialspoint/unix/test.sh"

 

if [ -r $file ]

then

   echo "File has read access"

else

   echo "File does not have read access"

fi

 

if [ -w $file ]

then

   echo "File has write permission"

else

   echo "File does not have write permission"

fi

 

if [ -x $file ]

then

   echo "File has execute permission"

else

   echo "File does not have execute permission"

fi

 

if [ -f $file ]

then

   echo "File is an ordinary file"

else

   echo "This is sepcial file"

fi

 

if [ -d $file ]

then

   echo "File is a directory"

else

   echo "This is not a directory"

fi

 

if [ -s $file ]

then

   echo "File size is zero"

else

   echo "File size is not zero"

fi

 

if [ -e $file ]

then

   echo "File exists"

else

   echo "File does not exist"

fi

运行结果:

File has read accessFile has write permissionFile has execute permissionFile is an ordinary fileThis is not a directoryFile size is zeroFile exists

 

文件测试运算符列表

操作符

说明

举例

-b file

检测文件是否是块设备文件,如果是,则返回 true。

[ -b $file ] 返回 false。

-c file

检测文件是否是字符设备文件,如果是,则返回 true。

[ -b $file ] 返回 false。

-d file

检测文件是否是目录,如果是,则返回 true。

[ -d $file ] 返回 false。

-f file

检测文件是否是普通文件(既不是目录,也不是设备文件),如果是,则返回 true。

[ -f $file ] 返回 true。

-g file

检测文件是否设置了 SGID 位,如果是,则返回 true。

[ -g $file ] 返回 false。

-k file

检测文件是否设置了粘着位(Sticky Bit),如果是,则返回 true。

[ -k $file ] 返回 false。

-p file

检测文件是否是具名管道,如果是,则返回 true。

[ -p $file ] 返回 false。

-u file

检测文件是否设置了 SUID 位,如果是,则返回 true。

[ -u $file ] 返回 false。

-r file

检测文件是否可读,如果是,则返回 true。

[ -r $file ] 返回 true。

-w file

检测文件是否可写,如果是,则返回 true。

[ -w $file ] 返回 true。

-x file

检测文件是否可执行,如果是,则返回 true。

[ -x $file ] 返回 true。

-s file

检测文件是否为空(文件大小是否大于0),不为空返回 true。

[ -s $file ] 返回 true。

-e file

检测文件(包括目录)是否存在,如果是,则返回 true。

[ -e $file ] 返回 true。

 

十、Shell注释

 

“#”开头的行就是注释,会被解释器忽略。

sh里没有多行注释,只能每一行加一个#号。只能像这样:

#--------------------------------------------

这是一个自动打ipa的脚本,基于webfrogsipa-build书写:

# https://github.com/webfrogs/xcode_shell/blob/master/ipa-build

 

功能:自动为etao ios app打包,产出物为14个渠道的ipa

特色:全自动打包,不需要输入任何参数

#--------------------------------------------

 

##### 用户配置区 开始 #####

#

#

项目根目录,推荐将此脚本放在项目的根目录,这里就不用改了

应用名,确保和XcodeProduct下的target_name.app名字一致

#

##### 用户配置区 结束  #####

如果在开发过程中,遇到大段的代码需要临时注释起来,过一会儿又取消注释,怎么办呢?每一行加个#符号太费力了,可以把这一段要注释的代码用一对花括号括起来,定义成一个函数,没有地方调用这个函数,这块代码就不会执行,达到了和注释一样的效果。

 

十一、Shell字符串

 

字符串是shell编程中最常用最有用的数据类型(除了数字和字符串,也没啥其它类型好用了),字符串可以用单引号,也可以用双引号,也可以不用引号。单双引号的区别跟PHP类似。

单引号

str='this is a string'

单引号字符串的限制:

单引号里的任何字符都会原样输出,单引号字符串中的变量是无效的;

单引号字串中不能出现单引号(对单引号使用转义符后也不行)。

双引号

your_name='qinjx'

str="Hello, I know your are \"$your_name\"! \n"

双引号的优点:

双引号里可以有变量

双引号里可以出现转义字符

拼接字符串

your_name="qinjx"

greeting="hello, "$your_name" !"

greeting_1="hello, ${your_name} !"

 

echo $greeting $greeting_1

获取字符串长度

string="abcd"

echo ${#string} #输出 4

提取子字符串

string="alibaba is a great company"

echo ${string:1:4} #输出liba

查找子字符串

复制纯文本新窗口

string="alibaba is a great company"

echo `expr index "$string" is`

 

十二、Shell数组:shell数组的定义、数组长度

 

Shell在编程方面比Windows批处理强大很多,无论是在循环、运算。

bash支持一维数组(不支持多维数组),并且没有限定数组的大小。类似与C语言,数组元素的下标由0开始编号。获取数组中的元素要利用下标,下标可以是整数或算术表达式,其值应大于或等于0

定义数组

Shell中,用括号来表示数组,数组元素用“空格”符号分割开。定义数组的一般形式为:
    array_name=(value1 ... valuen)
例如:

array_name=(value0 value1 value2 value3)

或者

array_name=(

value0

value1

value2

value3

)


还可以单独定义数组的各个分量:

array_name[0]=value0

array_name[1]=value1

array_name[2]=value2

可以不使用连续的下标,而且下标的范围没有限制。

读取数组

读取数组元素值的一般格式是:
      ${array_name[index]}
例如:

valuen=${array_name[2]}

举个例子:

#!/bin/sh

 

NAME[0]="Zara"

NAME[1]="Qadir"

NAME[2]="Mahnaz"

NAME[3]="Ayan"

NAME[4]="Daisy"

echo "First Index: ${NAME[0]}"

echo "Second Index: ${NAME[1]}"

运行脚本,输出:

$./test.shFirst Index: ZaraSecond Index: Qadir

使用或 可以获取数组中的所有元素,例如:

${array_name[*]}

${array_name[@]}

举个例子:

#!/bin/sh

 

NAME[0]="Zara"

NAME[1]="Qadir"

NAME[2]="Mahnaz"

NAME[3]="Ayan"

NAME[4]="Daisy"

echo "First Method: ${NAME[*]}"

echo "Second Method: ${NAME[@]}"

运行脚本,输出:

$./test.shFirst Method: Zara Qadir Mahnaz Ayan DaisySecond Method: Zara Qadir Mahnaz Ayan Daisy

 

获取数组的长度

获取数组长度的方法与获取字符串长度的方法相同,例如:

复制纯文本新窗口

取得数组元素的个数

length=${#array_name[@]}

或者

length=${#array_name[*]}

取得数组单个元素的长度

lengthn=${#array_name[n]}

 

十三、Shell echo命令

 

echoShell的一个内部指令,用于在屏幕上打印出指定的字符串。命令格式:

echo arg

您可以使用echo实现更复杂的输出格式控制。

显示转义字符

echo "\"It is a test\""

结果将是:
"It is a test"

双引号也可以省略。

显示变量

name="OK"

echo "$name It is a test"

结果将是:
OK It is a test



同样双引号也可以省略。

如果变量与其它字符相连的话,需要使用大括号({ }):

mouth=8

echo "${mouth}-1-2009"

结果将是:
8-1-2009

显示换行

echo "OK!\n"

echo "It is a test"

输出:
OK!
It is a test

显示不换行

echo "OK!\c"

echo "It is a test"

输出:
OK!It si a test

显示结果重定向至文件

echo "It is a test" > myfile

原样输出字符串

若需要原样输出字符串(不进行转义),请使用单引号。例如:

echo '$name\"'

显示命令执行结果

echo `date`

结果将显示当前日期

从上面可看出,双引号可有可无,单引号主要用在原样输出中。

 

十四、shell printf命令:格式化输出语句

 

printf 命令用于格式化输出, 是echo命令的增强版。它是C语言printf()库函数的一个有限的变形,并且在语法上有些不同。

注意:printf 由 POSIX 标准所定义,移植性要比 echo 好。

如同 echo 命令,printf 命令也可以输出简单的字符串:

$printf "Hello, Shell\n"

Hello, Shell

$

printf 不像 echo 那样会自动换行,必须显式添加换行符(\n)

printf 命令的语法:

printf  format-string  [arguments...]

format-string 为格式控制字符串,arguments 为参数列表。

printf()C语言入门教程中已经讲到,功能和用法与 printf 命令类似,请查看:C语言格式输出函数printf()详解

这里仅说明与C语言printf()函数的不同:

1printf 命令不用加括号

2format-string 可以没有引号,但最好加上,单引号双引号均可。

3参数多于格式控制符(%)时,format-string 可以重用,可以将所有参数都转换。

4arguments 使用空格分隔,不用逗号。


请看下面的例子:

# format-string为双引号

$ printf "%d %s\n" 1 "abc"

1 abc

单引号与双引号效果一样

$ printf '%d %s\n' 1 "abc"

1 abc

没有引号也可以输出

$ printf %s abcdef

abcdef

格式只指定了一个参数,但多出的参数仍然会按照该格式输出,format-string 被重用

$ printf %s abc def

abcdef

$ printf "%s\n" abc def

abc

def

$ printf "%s %s %s\n" a b c d e f g h i j

a b c

d e f

g h i

j

如果没有 arguments,那么 %s NULL代替,%d 用 代替

$ printf "%s and %d \n"

and 0

如果以 %d 的格式来显示字符串,那么会有警告,提示无效的数字,此时默认置为 0

$ printf "The first program always prints'%s,%d\n'" Hello Shell

-bash: printf: Shell: invalid number

The first program always prints 'Hello,0'

$


注意:根据POSIX标准,浮点格式%e%E%f%g%G是“不需要被支持”。这是因为awk支持浮点预算,且有它自己的printf语句。这样Shell程序中需要将浮点数值进行格式化的打印时,可使用小型的awk程序实现。然而,内建于bashksh93zsh中的printf命令都支持浮点格式。

 

十五、Shell if else语句

 

if 语句通过关系运算符判断表达式的真假来决定执行哪个分支。Shell 有三种 if ... else 语句:

Aif ... fi 语句;

Bif ... else ... fi 语句;

Cif ... elif ... else ... fi 语句。

1) if ... else 语句

if ... else 语句的语法:

if [ expression ]then   Statement(s) to be executed if expression is truefi

如果 expression 返回 truethen 后边的语句将会被执行;如果返回 false,不会执行任何语句。

最后必须以 fi 来结尾闭合 iffi 就是 if 倒过来拼写,后面也会遇见。

注意:expression 和方括号([ ])之间必须有空格,否则会有语法错误。

举个例子:

#!/bin/sh

 

a=10

b=20

 

if [ $a == $b ]

then

   echo "a is equal to b"

fi

 

if [ $a != $b ]

then

   echo "a is not equal to b"

fi

运行结果:

a is not equal to b

2) if ... else ... fi 语句

if ... else ... fi 语句的语法:

if [ expression ]then   Statement(s) to be executed if expression is trueelse   Statement(s) to be executed if expression is not truefi

如果 expression 返回 true,那么 then 后边的语句将会被执行;否则,执行 else 后边的语句。

举个例子:

#!/bin/sh

 

a=10

b=20

 

if [ $a == $b ]

then

   echo "a is equal to b"

else

   echo "a is not equal to b"

fi

执行结果:

a is not equal to b

3) if ... elif ... fi 语句

if ... elif ... fi 语句可以对多个条件进行判断,语法为:

if [ expression 1 ]then   Statement(s) to be executed if expression 1 is trueelif [ expression 2 ]then   Statement(s) to be executed if expression 2 is trueelif [ expression 3 ]then   Statement(s) to be executed if expression 3 is trueelse   Statement(s) to be executed if no expression is truefi

哪一个 expression 的值为 true,就执行哪个 expression 后面的语句;如果都为 false,那么不执行任何语句。

举个例子:

#!/bin/sh

 

a=10

b=20

 

if [ $a == $b ]

then

   echo "a is equal to b"

elif [ $a -gt $b ]

then

   echo "a is greater than b"

elif [ $a -lt $b ]

then

   echo "a is less than b"

else

   echo "None of the condition met"

fi

运行结果:

a is less than b


if ... else 语句也可以写成一行,以命令的方式来运行,像这样:

if test $[2*3] -eq $[1+5]; then echo 'The two numbers are equal!'; fi;


if ... else 语句也经常与 test 命令结合使用,如下所示:

num1=$[2*3]

num2=$[1+5]

if test $[num1] -eq $[num2]

then

    echo 'The two numbers are equal!'

else

    echo 'The two numbers are not equal!'

fi

输出:

The two numbers are equal!

test 命令用于检查某个条件是否成立,与方括号([ ])类似。

 

十六、Shell case esac语句

 

case ... esac 与其他语言中的 switch ... case 语句类似,是一种多分枝选择结构。

case 语句匹配一个值或一个模式,如果匹配成功,执行相匹配的命令。case语句格式如下:

case 值 in模式1)    command1    command2    command3    ;;模式2    command1    command2    command3    ;;*)    command1    command2    command3    ;;esac

case工作方式如上所示。取值后面必须为关键字 in,每一模式必须以右括号结束。取值可以为变量或常数。匹配发现取值符合某一模式后,其间所有命令开始执行直至 ;;;; 与其他语言中的 break 类似,意思是跳到整个 case 语句的最后。

取值将检测匹配的每一个模式。一旦模式匹配,则执行完匹配模式相应命令后不再继续其他模式。如果无一匹配模式,使用星号 * 捕获该值,再执行后面的命令。

下面的脚本提示输入14,与每一种模式进行匹配:

echo 'Input a number between 1 to 4'

echo 'Your number is:\c'

read aNum

case $aNum in

    1)  echo 'You select 1'

    ;;

    2)  echo 'You select 2'

    ;;

    3)  echo 'You select 3'

    ;;

    4)  echo 'You select 4'

    ;;

    *)  echo 'You do not select a number between 1 to 4'

    ;;

esac

输入不同的内容,会有不同的结果,例如:

Input a number between 1 to 4Your number is:3You select 3


再举一个例子:

#!/bin/bash

 

option="${1}"

case ${option} in

   -f) FILE="${2}"

      echo "File name is $FILE"

      ;;

   -d) DIR="${2}"

      echo "Dir name is $DIR"

      ;;

   *)

      echo "`basename ${0}`:usage: [-f file] | [-d directory]"

      exit 1 # Command to come out of the program with status 1

      ;;

esac

运行结果:

$./test.shtest.sh: usage: [ -f filename ] | [ -d directory ]$ ./test.sh -f index.htm$ vi test.sh$ ./test.sh -f index.htmFile name is index.htm$ ./test.sh -d unixDir name is unix$

aNum in

        1|2|3|4|5) echo "Your number is $aNum!"

        ;;

        *) echo "You do not select a number between 1 to 5!"

            continue

            echo "Game is over!"

        ;;

    esac

done

运行代码发现,当输入大于5的数字时,该例中的循环不会结束,语句

echo "Game is over!"

永远不会被执行。

同样,continue 后面也可以跟一个数字,表示跳出第几层循环。

再看一个 continue 的例子:

#!/bin/bash

 

NUMS="1 2 3 4 5 6 7"

 

for NUM in $NUMS

do

   Q=`expr $NUM % 2`

   if [ $Q -eq 0 ]

   then

      echo "Number is an even number!!"

      continue

   fi

   echo "Found odd number"

done

运行结果:

Found odd numberNumber is an even number!!Found odd numberNumber is an even number!!Found odd numberNumber is an even number!!Found odd number










本文转自 KaliArch 51CTO博客,原文链接:http://blog.51cto.com/kaliarch/1897003,如需转载请自行联系原作者
目录
相关文章
|
8月前
|
运维 Shell Linux
linux&shell
linux和shell的基础知识
|
9月前
|
Shell Linux
Linux shell 2>&1 深入理解
Linux shell 2>&1 深入理解
89 0
|
10月前
|
关系型数据库 MySQL Shell
Linux的shell之一
Shell 基本上是一个命令解释器,其接收用户命令,然后调用相应的应用程序来执行这些命令。Shell在计算机系统中的位置
|
11月前
|
Shell Linux
【linux】在 shell 中的";" 和 "&&"
【linux】在 shell 中的";" 和 "&&"
121 0
|
Shell Linux
Linux 有问必答:如何知道当前正在使用的 shell 是哪个?
Linux 有问必答:如何知道当前正在使用的 shell 是哪个? 问题: 我经常在命令行中切换 shell。是否有一个快速简便的方法来找出我当前正在使用的 shell 呢?此外,我怎么能找到当前 shell 的版本? 找到你当前正在使用的 Shell 版本 有多种方式可以查看你目前在使用什么 shell,最简单的方法就是通过使用 shell 的特殊参数。
11099 0
|
前端开发 Shell Linux
|
Shell Linux C语言