maoruibin / maoruibin/maoruibin.github.com
Shell 语法记录
Open
Nobody has claimed this yet.
article
blog
笔记
- Dominant language
- HTML
- Stars
- 22
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Description
把一个数组作为参数传递给 Shell 脚本
modules=($1)
for moduleDir in ${modules[@]}
do
echo $moduleDir
done
./createBranch.sh '132 323 323'
获取命令的输出结果
比如在执行了 git status 后,想要拿到结果,并进行赋值,可通过 `` 实现
status=`git status`
echo $status
在字符串中进行查找
grep 方法
status=`git status`
cleanStatus="nothing to commit"
result=$(echo $status | grep "${cleanStatus}")
if [[ "$result" != "" ]]
then
echo ""
else
echo $moduleDir" 模块尚有代码未提交,或者有其他更改,请先检查后,在选择创建分支"
fi
字符串特定字符替换
string="a,b,c,d"
echo $string
res="${string//,/$'-'}"
echo $res
如果要替换特殊字符,则需要转义
如 ' -> '
判断字符是否为空
STRING=
# 空判断
if [ -z "$STRING" ]; then
echo "STRING is empty"
fi
# 非空判断
if [ -n "$STRING" ]; then
echo "STRING is not empty"
fi
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue mentions createBranch.sh and shell examples using git status, grep, substitution, and string tests; first locate the blog source page where this note belongs. Review the examples for the intended documentation scope, then confirm the page renders correctly and that the documented commands remain understandable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git, shell
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100