导航:首页 > 操作系统 > linuxsh

linuxsh

发布时间:2022-01-22 11:48:17

1. linux shell #* 是什么意思

这是 变量扩展表达式。
"#* " 是指从变量host中删除空格前面的所有字符
一下摘取自 bash manual

${parameter#word}
${parameter##word}
The word is expanded to proce a pattern just as in filename expansion (see section 3.5.8 Filename Expansion). If the pattern matches the beginning of the expanded value of parameter, then the result of the expansion is the expanded value of parameter with the shortest matching pattern (the `#' case) or the longest matching pattern (the `##' case) deleted. If parameter is `@' or `*', the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with `@' or `*', the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.
${parameter%word}
${parameter%%word}
The word is expanded to proce a pattern just as in filename expansion. If the pattern matches a trailing portion of the expanded value of parameter, then the result of the expansion is the value of parameter with the shortest matching pattern (the `%' case) or the longest matching pattern (the `%%' case) deleted. If parameter is `@' or `*', the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with `@' or `*', the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.
${parameter/pattern/string}
${parameter//pattern/string}

The pattern is expanded to proce a pattern just as in filename expansion. Parameter is expanded and the longest match of pattern against its value is replaced with string. In the first form, only the first match is replaced. The second form causes all matches of pattern to be replaced with string. If patternbegins with `#', it must match at the beginning of the expanded value of parameter. If pattern begins with `%', it must match at the end of the expanded value of parameter. If string is null, matches of pattern are deleted and the / following pattern may be omitted. If parameter is `@' or `*', the substitution operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with `@' or `*', the substitution operation is applied to each member of the array in turn, and the expansion is the resultant list.

${parameter:-word}
If parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parameter is substituted.
${parameter:=word}
If parameter is unset or null, the expansion of word is assigned to parameter. The value of parameter is then substituted. Positional parameters and special parameters may not be assigned to in this way.
${parameter:?word}
If parameter is null or unset, the expansion of word (or a message to that effect if word is not present) is written to the standard error and the shell, if it is not interactive, exits. Otherwise, the value of parameter is substituted.
${parameter:+word}
If parameter is null or unset, nothing is substituted, otherwise the expansion of word is substituted.
${parameter:offset}
${parameter:offset:length}
Expands to up to length characters of parameter starting at the character specified by offset. If length is omitted, expands to the substring of parameter starting at the character specified by offset. length and offset are arithmetic expressions (see section 6.5 Shell Arithmetic). This is referred to as Substring Expansion.

length must evaluate to a number greater than or equal to zero. If offset evaluates to a number less than zero, the value is used as an offset from the end of the value of parameter. If parameter is `@', the result is length positional parameters beginning at offset. If parameter is an array name indexed by `@' or`*', the result is the length members of the array beginning with ${parameter[offset]}. Substring indexing is zero-based unless the positional parameters are used, in which case the indexing starts at 1.
${!prefix*}
Expands to the names of variables whose names begin with prefix, separated by the first character of the IFS special variable.
${#parameter}
The length in characters of the expanded value of parameter is substituted. If parameter is `*' or `@', the value substituted is the number of positional parameters. If parameter is an array name subscripted by `*' or `@', the value substituted is the number of elements in the array.

2. linux中 sh是什么文件

sh是脚本文件,使用vim xx.sh可以打开编辑文件。sh xx.sh可以执行该脚本文件

3. Linux 脚本 sh 和 ./ 的区别

区别只有一点:

sh表示脚本默认使用sh脚本解释器。

未指定脚本解释器默认为 ./。

具体解释:

使用“./”执行脚本,对应的xxx.sh脚本必须要有执行权限。

使用“sh” 执行脚本,对应的xxx.sh没有执行权限,亦可执行。

当脚本开头使用#!设置使用的shell类型时,使用“./”执行脚本时,则使用“#!”标志的shell执行脚本;若无使用“#!”标记,则使用系统设置的默认shell执行脚本。

(3)linuxsh扩展阅读:

举例:

登录用户root查看权限:

-rwx—— 1 root root

执行这个shell脚本 :

./test 成功。

sh test 成功。

去掉执行权限x:

-rw——- 1 root root 17 2011-09-22 23:33 test

执行这个shell脚本。

./test 失败 (-bash: ./test: Permission denied)。

sh test 成功。

4. Linux shell 脚本中, $@ 和$# 分别是什么意思

直接看示例:
[root@localhost xly]# cat t.sh
#!/bin/bash
echo $#
echo $@
[root@localhost xly]# sh t.sh
0
[root@localhost xly]# sh t.sh a b c
3
a b c
说明:
$@表示所有参数
$#表示所有参数的个数

5. 怎么创建.sh 文件(linux)

创建方法如下:

1、touch hello.sh

2、vim hello.sh

键入i

插入#!/bin/sh

echo hello world;

键入:

esc

:

wq

3、chmod 700 hello.sh

4.、执行./hello.sh

(5)linuxsh扩展阅读:

关于linux shell 文件的操作总结

1、创建文件夹

#!/bin/sh

mkdir -m 777 "%%1"

2、创建文件

#!/bin/sh

touch "%%1"

3、删除文件

#!/bin/sh

rm -if "%%1"

4、删除文件夹

#!/bin/sh

rm -rf "%%1"

5、删除一个目录下所有的文件夹

#!/bin/bash

direc="%%1" #$(pwd)

for dir2del in $direc/* ; do

if [ -d $dir2del ]; then

rm -rf $dir2del
fi
done

6、清空文件夹

#!/bin/bash

direc="%%1" #$(pwd)

rm -if $direc/*

for dir2del in $direc/* ; do

if [ -d $dir2del ]; then

rm -rf $dir2del

fi

done

7、读取文件

#!/bin/sh

6. linux 命令中的sh是什么意思

1、sh是linux中运行shell的命令,是shell的解释器,shell脚本是linux中壳层与命令行界面,用户可以在shell脚本输入命令来执行各种各样的任务。

要运行shell脚本,首选需要给shell脚本权限,这里里以hello.sh文件为例,首先需要按下“crtl+shift+T”打开终端窗口:

7. Linux下面如何运行 SH文件

本文介绍Linux下面用命令如何运行.sh文件的方法,有两种方法:

一、直接./加上文件名.sh,如运行hello.sh为./hello.sh【hello.sh必须有x权限】

二、直接sh 加上文件名.sh,如运行hello.sh为sh hello.sh【hello.sh可以没有x权限】

工具/原料

8. linux ./a.sh 命令 与sh a.sh的区别是什么

linux ./a.sh 命令 与sh a.sh的区别为:可执行属性不同、执行方式不同、兼容性不同。

一、可执行属性不同

1、./a.sh 命令:./a.sh 命令的文件必须具有可执行属性。

2、sh a.sh命令:sh a.sh命令的文件不必具有可执行属性。

二、执行方式不同

1、./a.sh 命令:./a.sh 命令使用脚本中第一行所指定的命令来解释和执行文件。

2、sh a.sh命令:sh a.sh命令使用shell工具的SH脚本直接解释和执行文件。

三、兼容性不同

1、./a.sh 命令:./a.sh 命令的兼容性比sh a.sh命令更好,不受限于shell工具。

2、sh a.sh命令:sh a.sh命令的兼容性比./a.sh 命令更差,受限于shell工具。

阅读全文

与linuxsh相关的资料

热点内容
linuxc编程高级 浏览:725
python解码vip视频 浏览:585
丑陋的中国人pdf 浏览:717
我的世界如何在服务器里面装模组 浏览:622
javaweb进销存源码下载 浏览:555
单片机遥控门铃设计图解 浏览:322
闪送app怎么更改照片 浏览:158
公司的程序员开始忙了 浏览:504
统信系统命令行如何输汉字 浏览:279
java随机取数组 浏览:476
服务器匆忙什么意思 浏览:780
windows下载文件命令 浏览:101
绍兴加密防伪技术 浏览:54
linux清除缓存的命令 浏览:779
梁柱连接处梁的加密箍筋 浏览:103
安卓录屏大师如何弹出 浏览:658
cad命令详解 浏览:173
品牌云服务器提供商 浏览:326
加密投资者的心理 浏览:700
小米无命令 浏览:826