shell指令碼的引用用法說明

來源:互聯網
上載者:User

標籤:between   current   quotes   single   單引號   引用   

#!/bin/bash
#示範全引用和部分引用
#雙引號和沒引號的區別
variable1=2010
echo "$variable1"
echo $variable1
variable2="x    y     z"    ##字元之間用多個空格隔開
echo "$variable2"           ##雙引號
echo $variable2             ##沒引號

#單引號和雙引號的區別
echo "$PWD is the current directory."  ##雙引號
echo ‘$PWD is the current direcotry.‘  ##單引號

#單引號的問題和解決方案
echo "Why can‘t I write‘s between single quotes"  ##單引號出現的問題
echo ‘Why can‘"‘"‘t I write‘"‘"‘s between single quotes‘  ##解決單引號的問題

##命令替換
#反引號的用法
echo `world`       ##調用world命令
echo `who`         ##調用who命令

#字串分割問題與解決辦法
echo `echo`         ##表示將結果以欄位顯示
echo "`echo`"       ##表示將結果以字串顯示
echo `echo x y`     ##表示結果是x y兩個字串
echo "`echo x y`"   ##表示結果是x y為一個字串

dirlist=`ls -l *`   ##命令替換
echo $dirlist       ##不引用dirlist變數,分行符號被刪除
echo "$dirlist"     ##引用dirlist變數,分行符號保留

#$()的嵌套用法
firstlinelength=$(expr length "$(sed -n ‘1p‘ *)")
echo $firstlinelength

#轉義
echo \\         ##輸出轉義符
echo `echo \\`   ##輸出空本行
echo $(echo \\)  ##輸出單斜線符

#轉義符的運用
echo "\$PWD"                            ##轉義$符號
echo "This is \" The 60th National Day\""  ##轉義雙引號"
echo "\\"                              ##轉義符號本身
variable=\               ##將轉義符賦值給變數

#將一串符號賦值非變數
variable="()\\{}\$""      
echo $variable        
echo "$variable"

IFS=‘\‘
echo $variable
echo "$variable" 


本文出自 “盡夜” 部落格,請務必保留此出處http://endmoon.blog.51cto.com/8921900/1616630

shell指令碼的引用用法說明

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.