bash shell function傳入有含空格的變數 - Linux

By Ula
at 2014-10-11T15:03
at 2014-10-11T15:03
Table of Contents
最近剛開始學bash shell 遇到一個問題
如果我今天寫一個function
function printSth(){
echo $1
}
我要傳入的變數是
myVar="Hello World"
但我如果單純下指令:
printSth myVar
他只會印出Hello,而World就會被他當成第二個變數而沒有印出
請問有甚麼方法讓我傳入的變數可以包含空格嗎
(有試過跳脫字元也沒用 "Hello\ World")
感謝!
--
如果我今天寫一個function
function printSth(){
echo $1
}
我要傳入的變數是
myVar="Hello World"
但我如果單純下指令:
printSth myVar
他只會印出Hello,而World就會被他當成第二個變數而沒有印出
請問有甚麼方法讓我傳入的變數可以包含空格嗎
(有試過跳脫字元也沒用 "Hello\ World")
感謝!
--
Tags:
Linux
All Comments

By Michael
at 2014-10-14T18:31
at 2014-10-14T18:31

By Caroline
at 2014-10-18T07:17
at 2014-10-18T07:17
Related Posts
tomcat的performance

By Tristan Cohan
at 2014-10-11T14:40
at 2014-10-11T14:40
在 Mint 17 安裝 Oracle Java 的方法

By Frederic
at 2014-10-11T02:13
at 2014-10-11T02:13
root LV not available 無法mount

By Elizabeth
at 2014-10-09T23:09
at 2014-10-09T23:09
openwrt中uci config 如何跟程式連動

By Harry
at 2014-10-09T17:52
at 2014-10-09T17:52
host為Ubuntu下的VirtualBox USB裝置

By Barb Cronin
at 2014-10-09T16:51
at 2014-10-09T16:51