Bash Arge

Example

Simple Example

1
2
3
#!/bin/bash
echo "$1"
echo "$@"

测试命令

1
bash script.sh 1 2 3

输出结果是

1
2
1
1 2 3

分割参数

1
2
3
4
5
6
7
8
9
10
11
#!/bin/bash
echo "args:$@"

arg=$1
echo "arg: $1"

beforedot=${arg%.*}
afterdot=${arg#*.}

echo $beforedot
echo $afterdot

测试命令

1
bash ./test.sh 1.2.3.4.5

输出结果

1
2
3
4
args:1.2.3.4.5
arg: 1.2.3.4.5
1.2.3.4
2.3.4.5