bash 언어 기초
21647 단어 linux
$0,$1/$2..$0
,$1、$2... N
$#
"$*"
("$1$2…")
"$@"
("$1""$2"…)
$-
shell , set
$?
, , 0
$$
ID
$!
ID
1、 #
#!/bin/bash #
2、 $ 。
, , $a a 。
1 , {}
3、
,
, , 。
echo ‘my $SHELL’
4、
, $ \ ` //`
, 。
5、 ( 1 )
shell ,
。
6.
。
(\) shell 。
.. , cd
.
*
?
[..]
\m , *、?
[a-z] *
\ ,
~
; , ,
$ BourneShell , shell
#
| ,
&
>
< , >
>>
{..}
수치 처리
num1 –eq num2 num1 num2,
num1 –gt num2 num1 num2,
num1 –lt num2 num1 num2,
num1 –ge num2 num1 num2,
num1 –le num2 num1 num2,
num1 –ne num2 num1 num2,
expr
r=`expr 4 + 5`
r=`expr 40 -5`
r=`expr 4 \* 5` // \* *
r=`expr 40 / 5`
r=`expr 100 % 43`
:expr
$(())
r=$(( 4 + 5 ))
r=$(( 40 -5 ))
r=$(( 4 * 5 ))
r=$(( 40 / 5 ))
r=$((100 % 43))
r=$(( 2 ** 3 ))
$[]
r=$[ 4 + 5 ]
r=$[ 40 -5 ]
r=$[ 4 * 5 ]
r=$[ 40 / 5 ]
r=$[100 % 43]
r=$[ 2 ** 3 ]
let
let "r = 4+5"
let "r = 40 -5"
let "r = 4 * 5"
let "r = 40 / 5"
let "r = 100 % 43"
let "r = 2**3"
: ,=
문자열
문자열 상수
[:alpha:]
'[0-9]{3}[[:alpha:]]{2}' ,
[:alnum:]
、
'[[:alnum:]]+'
[:digit:]
'[[:digit:]-]+'
[:lower:]
。
'[[:lower:]]' A, A
[:space:]
(' ')
[[:space:]]
[:upper:]
'[[:upper:]ab]' : 、a b。
[:whitespace:]
、 、
[:ascii:]
ASCII 、 、
[:blank:]
[[:blank:]] [ \t]
문자열 일치 (포 지 셔 닝, 판단, 교체)
\b , 。
:“er\b” “never” “er”, “verb” “er”。
echo "never verb" |xargs -n1 |grep "er\b"
^
: abc :
echo –e “abc
xyz”|grep –E ^abc
$
: xyz
echo –e “abc
xyz”|grep –E xyz$
* 0
+ 1
? 0 1
{n} N
{n,} N
{n,m} n m
[] ,
() ( )
*? ,
+? 1 ,
?? 0 1 ,
email
^[a-zA-Z0-9_]+@[a-zA-Z0-9_]+\.[a-zA-Z0-9_]+$
:
^[a-zA-Z0-9_]+
@
[a-zA-Z0-9_]+
\.
[a-zA-Z0-9_]+$
QQ :[1-9][0-9]{4,}
.
\s ——[ \f
\r\t\v]
\S ——[^ \f
\r\t\v]
\w 、 、 ——[A-Za-z0-9_]
\W 、 、 ——[^A-Za-z0-9_]
\d 0-9——[0-9]
\D ——[^0-9]
-n string string
-z string string
String1=string2 string1 string2
String1!=string2 string1 string2
: , , ;
${#string}
$string
${string:position}
$string , $position
${string:position:length}
$string , $position $length
${string#substring}
$string , $substring
${string##substring}
$string , $substring
${string%substring}
$string , $substring
${string%%substring}
$string , $substring
${string/old/new}
$new, $old
${string//old/new}
$new, $old
${string/#old/new}
. $string $old , $new
${string/%old/new}
. $string $old , $new
복합 조건
! expression
expression , 。!
expression1 –a expression2
expression1 expression2 ,
expression1 –o expression2
expression1 expression2 ,
구조 화 제어:
:
if : if then else
Case : 、
:
for: , 。
until: , 。
while: 。
continue: 。
break: , 。
1:
if[ ]
then
fi
2:
if[ ] ; then
fi
3:
if [ ]
then
1
else
2
fi
4:
if [ 1 ]
then
1
elif[ 2 ]
then
2
else
3
fi
case :
case in
1)
1
;;
2)
…
*)
n
;;
esac
// in, 。 。
// , , ;;
//***** 。
// , * 。
for 1
for in
do
done
for 2:
for (( = ; ; ))
do
done
:
s=0
for ((i=1;i<=100;i++))
do
s=$((s+i))
done
echo $s
while :
while
do
done
//while , 。
// , while do 。
// ,
// 0 ,do done ,
// 0, 。
until
until
do
done
until , 。
break continue for、while、until
break done , 。
continue done , 。
입 출력
Linux , 3 , :
:standard input 0。
, 。
:standard output 1。
。
:error output 2。
。
。
: , 。
: , 。
/dev/stdin0
/dev/stdout1
/dev/stderr2
“<”: , , , 。
“>>”: , 。
“>”: 。
read a < 1.txt
echo $a
>
>>
2>
2>>
> 2>&1
>> 2>&1
&>
&>>
>> 1 2>> 2
&>/dev/null
// /dev/null
// .
cat filename >/dev/null
rm filename1 2>/dev/null
rm filename1 >/dev/null 2>&1
cat /dev/null > filename
ls –l >/dev/null 2>&1 === &>/dev/null
함수.
:1. ; 2.
:
, shell 。
, shell, 。
, 。
, ,shell 。
, 。
, 。
()
{
. . .
}
function ()
{
…
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
용감한 바로 가기 및 우분투 응용 프로그램안녕하세요 여러분, 이 기사에서는 모든 사이트에서 pwa를 생성하고 실행기 응용 프로그램으로 추가하는 방법을 설명하고 싶습니다. 일부 웹사이트는 PWA로 설치를 허용하지 않지만 유사한 애플리케이션을 원합니다. 1. ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.