亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1622 | 回復: 4
打印 上一主題 下一主題

關于雙引號的困惑 [復制鏈接]

論壇徽章:
0
跳轉到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2010-03-23 17:44 |只看該作者 |倒序瀏覽
腳本A

#!/bin/bash
if [ "${x+X}" = X ]  #if x is set
then
        if [ -n $x ] #if x is not empty
        then
        printf " \$x = %s\n" "$x"
        else
        printf " \$x is set but empty \n"
        fi
else
printf " \$x is not set.\n"
fi


腳本B

#!/bin/bash
if [ "${x+X}" = X ]  #if x is set
then
        if [ -n "$x" ] #if x is not empty
        then
        printf " \$x = %s\n" "$x"
        else
        printf " \$x is set but empty \n"
        fi
else
printf " \$x is not set.\n"
fi


紅色部分的不同,造成了腳本的運行錯誤,不加引號的話,即使變量x為空,打印出來卻是$x=     但是加上引號后,當x為空時,可以識別出來為空



但是我想不明白在這里$x 和"$x" 有什么區(qū)別,求教大俠。!

論壇徽章:
0
2 [報告]
發(fā)表于 2010-03-23 17:46 |只看該作者
試一下這樣:

'"$x"'

論壇徽章:
0
3 [報告]
發(fā)表于 2010-03-23 17:49 |只看該作者
'"$x"' 的的結果和$x一樣,無法識別空變量

論壇徽章:
5
2015年辭舊歲徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015年亞洲杯之朝鮮
日期:2015-03-13 22:47:33IT運維版塊每日發(fā)帖之星
日期:2016-01-09 06:20:00IT運維版塊每周發(fā)帖之星
日期:2016-03-07 16:27:44
4 [報告]
發(fā)表于 2010-03-23 18:12 |只看該作者
因為word splitting

論壇徽章:
0
5 [報告]
發(fā)表于 2010-03-23 18:55 |只看該作者
The shell scans the results of parameter expansion, command substitution, and arithmetic expansion that did not occur within double quotes for word splitting.

The shell treats each character of $IFS as a delimiter, and splits the results of the other expansions into words on these characters. If IFS is unset, or its value is exactly "'<space><tab><newline>'", the default, then any sequence of IFS characters serves to delimit words. If IFS has a value other than the default, then sequences of the whitespace characters "space" and "Tab" are ignored at the beginning and end of the word, as long as the whitespace character is in the value of IFS (an IFS whitespace character). Any character in IFS that is not IFS whitespace, along with any adjacent IF whitespace characters, delimits a field. A sequence of IFS whitespace characters is also treated as a delimiter. If the value of IFS is null, no word splitting occurs.

Explicit null arguments ("""" or "''") are retained. Unquoted implicit null arguments, resulting from the expansion of parameters that have no values, are removed. If a parameter with no value is expanded within double quotes, a null argument results and is retained.


Expansion and word splitting
  If no expansion occurs, no splitting is performed.
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術有限公司. 版權所有 京ICP備16024965號-6 北京市公安局海淀分局網監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關心和支持過ChinaUnix的朋友們 轉載本站內容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP