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

  免費注冊 查看新帖 |

Chinaunix

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

[文本處理] shell命令結(jié)果重定向到文件,如果文件只讀導(dǎo)致... [復(fù)制鏈接]

論壇徽章:
1
數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2015-09-19 06:20:00
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2016-01-05 10:49 |只看該作者 |倒序瀏覽
我們經(jīng)常在腳本中這么使用

例如:

SHLIST=`ls 2>>/var/log/test`
SHLIST=`ls 2>>/var/log`

但是假如/var/log/test是個只讀文件或者log是個目錄等等吧,各種以外情況,

會導(dǎo)致,提示說xxx文件有問題

echo $SHLIST輸出為空

請問如何規(guī)避這個問題,就是說:
無論重定向的文件是好是壞,不影響我前面命令的執(zhí)行

論壇徽章:
145
技術(shù)圖書徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11獅子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龍
日期:2014-01-08 15:26:12技術(shù)圖書徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
2 [報告]
發(fā)表于 2016-01-05 10:58 |只看該作者
回復(fù) 1# 螃蟹009

SHLIST=`ls 2>>/dev/null`
   

論壇徽章:
1
數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2015-09-19 06:20:00
3 [報告]
發(fā)表于 2016-01-05 11:00 |只看該作者
回復(fù) 2# jason680


    某些特殊情況文件有問題(有問題時候希望他不影響前面程序的執(zhí)行),但是沒有問題時候又希望可以正常記錄

論壇徽章:
145
技術(shù)圖書徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11獅子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龍
日期:2014-01-08 15:26:12技術(shù)圖書徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
4 [報告]
發(fā)表于 2016-01-05 11:07 |只看該作者
回復(fù) 3# 螃蟹009

check file before using
   
$ man bash
...

       When  used with [[, the < and > operators sort lexicographically using
       the current locale.  The test command sorts using ASCII ordering.

       -a file
              True if file exists.
       -b file
              True if file exists and is a block special file.
       -c file
              True if file exists and is a character special file.
       -d file
              True if file exists and is a directory.
       -e file
              True if file exists.
       -f file
              True if file exists and is a regular file.

       -g file
              True if file exists and is set-group-id.
       -h file
              True if file exists and is a symbolic link.
       -k file
              True if file exists and its ``sticky'' bit is set.
       -p file
              True if file exists and is a named pipe (FIFO).
       -r file
              True if file exists and is readable.
       -s file
              True if file exists and has a size greater than zero.
       -t fd  True if file descriptor fd is open and refers to a terminal.
       -u file
              True if file exists and its set-user-id bit is set.
       -w file
              True if file exists and is writable.

       -x file
              True if file exists and is executable.
       -G file
              True if file exists and is owned by the effective group id.
       -L file
              True if file exists and is a symbolic link.
       -N file
              True if file exists and has been modified  since  it  was  last
              read.
       -O file
              True if file exists and is owned by the effective user id.
       -S file
              True if file exists and is a socket.
       ...

論壇徽章:
12
IT運維版塊每日發(fā)帖之星
日期:2015-11-17 06:20:00程序設(shè)計版塊每日發(fā)帖之星
日期:2016-01-19 06:20:0015-16賽季CBA聯(lián)賽之江蘇
日期:2016-01-17 15:31:3915-16賽季CBA聯(lián)賽之上海
日期:2016-01-16 15:44:3015-16賽季CBA聯(lián)賽之浙江
日期:2016-01-15 20:38:1815-16賽季CBA聯(lián)賽之北京
日期:2016-01-09 14:30:15CU十四周年紀念徽章
日期:2016-01-07 12:31:5115-16賽季CBA聯(lián)賽之四川
日期:2016-01-01 11:49:1515-16賽季CBA聯(lián)賽之深圳
日期:2015-12-24 14:23:4115-16賽季CBA聯(lián)賽之山西
日期:2015-12-15 16:22:31技術(shù)圖書徽章
日期:2015-12-10 17:41:0015-16賽季CBA聯(lián)賽之北控
日期:2016-02-03 10:03:24
5 [報告]
發(fā)表于 2016-01-05 11:57 |只看該作者
試試SHLIST=`ls 2|tee -a /var/log` 不過最好還是像樓上所說的check file before using

論壇徽章:
1
數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2015-09-19 06:20:00
6 [報告]
發(fā)表于 2016-01-05 12:42 |只看該作者
回復(fù) 5# sync_1521

這個就是我想要的,在用之前確實應(yīng)該做個檢查
   
您需要登錄后才可以回帖 登錄 | 注冊

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

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP