Linux學習之shell程式設計二

2021-06-21 00:25:50 字數 879 閱讀 9209

shell script 的預設變數

$0,$1......

$#:代表後接的引數個數

$@:代表$1,$2,$3,$4之意

$*:代表「$1c$2c$3c$4」,其中c為分隔符,預設為空格

shift:可以偏移變數號碼,比如shift ,或者shift  2可以將變數**向左移動1次或2次

#!/bin/bash

#filename:shell05.sh

echo "the number of variables is ==> $#"

echo "the total variable is ==> '$@'"

echo "the first variable is ==> $1"

shift #偏移一次

echo "the number of variables is ==> $#"

echo "the total variable is ==> '$@'"

echo "the first variable is ==> $1"

執行./shell05.sh  one two three four

得到結果:

the number of variables is ==> 4

the total variable is ==> 'one two three four'

the first variable is ==> one

the number of variables is ==> 3

the total variable is ==> 'two three four'

the first variable is ==> two

Linux學習之shell程式設計一

獲取變數的值可以使用 var或者 後者可以預防變數讀取錯誤。command 可以獲得命令的執行結果。1.shell指令碼的書寫格式 1 bin bash 2 程式說明 包括日期,作者,程式作用等資訊 3 path bin sbin usr bin usr sbin usr local bin usr...

Linux學習之Shell指令碼程式設計

一.shell指令碼定義 shell是系統的使用者介面,提供了使用者與核心進行互動操作的一種介面。它接收使用者輸入的命令並把它送入核心去執行。實際上shell是乙個命令直譯器,它解釋由使用者輸入的命令並且把它們送到核心。shell翻譯成殼的意思,它是包裹在linux核心外層的,乙個可通過一系列的li...

linux之shell程式設計

shell你只需要了解這麼多 補充 1.第七部分特殊字元的使用 特殊字元用在shell指令碼中即可 2.第八部分中轉義字元的理解 shell命令列中特殊字元與其轉義詳解 去除特殊含義 這部分主要給大家詳細介紹了shell命令列中特殊字元與其轉義 去除特殊含義 的相關資料,文中介紹的很詳細,相信對大家...