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
关于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权限】
工具/原料
windows、linux
xshell
方法一:当前目录执行.sh文件
1
【步骤一】cd到.sh文件所在目录
比如以hello.sh文件为例,如下图
注意事项
用“./”加文件名.sh执行时,必须给.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工具。