導航:首頁 > 操作系統 > 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相關的資料

熱點內容
醜陋的中國人pdf 瀏覽:717
我的世界如何在伺服器裡面裝模組 瀏覽:622
javaweb進銷存源碼下載 瀏覽:555
單片機遙控門鈴設計圖解 瀏覽:322
閃送app怎麼更改照片 瀏覽:158
公司的程序員開始忙了 瀏覽:504
統信系統命令行如何輸漢字 瀏覽:279
java隨機取數組 瀏覽:476
伺服器匆忙什麼意思 瀏覽:779
windows下載文件命令 瀏覽:100
紹興加密防偽技術 瀏覽:53
linux清除緩存的命令 瀏覽:778
樑柱連接處梁的加密箍筋 瀏覽:102
安卓錄屏大師如何彈出 瀏覽:658
cad命令詳解 瀏覽:173
品牌雲伺服器提供商 瀏覽:326
加密投資者的心理 瀏覽:700
小米無命令 瀏覽:826
不要層層等命令 瀏覽:373
4k播放器怎樣設置源碼 瀏覽:955