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

Ula avatar
By Ula
at 2014-10-11T15:03

Table of Contents

最近剛開始學bash shell 遇到一個問題
如果我今天寫一個function

function printSth(){
echo $1
}

我要傳入的變數是

myVar="Hello World"

但我如果單純下指令:

printSth myVar

他只會印出Hello,而World就會被他當成第二個變數而沒有印出

請問有甚麼方法讓我傳入的變數可以包含空格嗎
(有試過跳脫字元也沒用 "Hello\ World")

感謝!

--
Tags: Linux

All Comments

Michael avatar
By Michael
at 2014-10-14T18:31
一般都這樣用:printSth "$myvar"
Caroline avatar
By Caroline
at 2014-10-18T07:17
有道理耶! 感謝,被""、{}和空白迷惑中 總算快搞懂了

tomcat的performance

Tristan Cohan avatar
By Tristan Cohan
at 2014-10-11T14:40
tomcat 啟用時 在top 只看到 java 這支process吃了多少資源 請問有辦法看到細節嗎? 就是該process下各thread吃了多少資源 - ...

在 Mint 17 安裝 Oracle Java 的方法

Frederic avatar
By Frederic
at 2014-10-11T02:13
謝謝網友指點 修正原文如下: 作業系統 Linux Mint 17 Qiana Cinnamon 32 bit (安裝在硬碟) 按照以下網頁的方法 成功安裝了 Oracle Java 7 Install Oracle Java 8 In Ubuntu Via PPA Repository [JDK8] ...

root LV not available 無法mount

Elizabeth avatar
By Elizabeth
at 2014-10-09T23:09
各位版友大家好,我之前有PO過同一個問題 目前還沒解決,想再來請問大家 我的問題是本來我root空間不夠用,而我有使用LVM 然後我便用iscsi連了nas,讓我多一個磁碟可以用 然後我再把這磁碟建立PV,再把它加入root 的VG裡 然後再resize root LV的大小,完成,一切運作順利,r ...

openwrt中uci config 如何跟程式連動

Harry avatar
By Harry
at 2014-10-09T17:52
各位大大好 目前因為工作關係, 想要寫一個process 以及新增一些相關的 uci configuration 目前想要參照openwrt 的作法, 想要把程式跟 uci configuration 進行連動 因此現在在觀察uci 與 程式之間的連動關係 但是目前還沒看到程式 在 start 時候如 ...

host為Ubuntu下的VirtualBox USB裝置

Barb Cronin avatar
By Barb Cronin
at 2014-10-09T16:51
目前小弟在筆電上安裝Ubuntu 14.04 然後安裝Virtual box 但Virtual Box抓不到我筆電的讀卡機 (在設定-andgt;USB選項當中看不到裝置) 但在Win8.1下的Virtual Box卻可以抓到讀卡機(我筆電灌雙系統) Host端可以正常讀取SD卡,driver應該是有 ...