Skip to content

Instantly share code, notes, and snippets.

@lululau
Created January 22, 2013 15:48
Show Gist options
  • Save lululau/4595697 to your computer and use it in GitHub Desktop.
Save lululau/4595697 to your computer and use it in GitHub Desktop.
test
~ $ cat test.sh
#!/bin/bash
function hello() {
echo "ARG1: $1"
echo "ARG2: $2"
echo "ARG3: $3"
}
echo "ARG_1: $1"
echo "ARG_2: $2"
echo "ARG_3: $3"
echo "ARG_4: $4"
shift # 截掉第一个参数
hello "$@"
~ $ ./test.sh a b c 'd e' f
ARG_1: a
ARG_2: b
ARG_3: c
ARG_4: d e
ARG1: b
ARG2: c
ARG3: d e
@tousinn
Copy link

tousinn commented Jan 23, 2013

我找到解决方法了。
在shell执行的时候参数的写法像这样:

单引号双引号参数值双引号单引号

./test.sh a b c '"d e"' f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment