处理参数空格到bash脚本 [英] Handle whitespaces in arguments to a bash script
本文介绍了处理参数空格到bash脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有处理包含在我的bash脚本白色空格的参数问题。
I am having issues handling arguments that contain white spaces in a my bash script.
脚本
#!/bin/bash
for i in $*
do
echo "$i"
done
的调用(带2个参数)
$ ./script.sh "a b" "c"
的实际输出(好像有3个参数)
a
b
c
预期输出(好像有2个参数)
a b
c
有人能解释如何获得预期的输出?
Can someone explain how to get the expected output?
推荐答案
修改 $ *
到$ @
在第一行
这篇关于处理参数空格到bash脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文