【shell 】 test, /usr/bin/test, [ ], 和/usr/bin/[都是等價命令
test, /usr/bin/test, [ ], 和/usr/bin/[都是等價命令
#!/bin/bash
echo
if test -z "$1"
then
echo "No command-line arguments."
else
echo "First command-line argument is $1."
fi
echo
if /usr/bin/test -z "$1" # 與內建的"test"命令結果相同.
then
echo "No command-line arguments."
else
echo "First command-line argument is $1."
fi
echo
if [ -z "$1" ] # 與上邊的程式碼塊作用相同.
# if [ -z "$1" 應該能夠執行, 但是...
#+ Bash報錯, 提示缺少關閉條件測試的右中括號.
then
echo "No command-line arguments."
else
echo "First command-line argument is $1."
fi
echo
if /usr/bin/[ -z "$1" ] # 再來一個, 與上邊的程式碼塊作用相同.
# if /usr/bin/[ -z "$1" # 能夠工作, 但是還是給出一個錯誤訊息.
"vartify.sh" [New] 46L, 1086C written
root@client.example.com ~/yang # chmod 755 vartify.sh
root@client.example.com ~/yang # ./vartify.sh
No command-line arguments.
No command-line arguments.
No command-line arguments.
No command-line arguments.
root@client.example.com ~/yang # ./vartify.sh yangqilong
First command-line argument is yangqilong.
First command-line argument is yangqilong.
First command-line argument is yangqilong.
First command-line argument is yangqilong.
root@client.example.com ~/yang #
#!/bin/bash
echo
if test -z "$1"
then
echo "No command-line arguments."
else
echo "First command-line argument is $1."
fi
echo
if /usr/bin/test -z "$1" # 與內建的"test"命令結果相同.
then
echo "No command-line arguments."
else
echo "First command-line argument is $1."
fi
echo
if [ -z "$1" ] # 與上邊的程式碼塊作用相同.
# if [ -z "$1" 應該能夠執行, 但是...
#+ Bash報錯, 提示缺少關閉條件測試的右中括號.
then
echo "No command-line arguments."
else
echo "First command-line argument is $1."
fi
echo
if /usr/bin/[ -z "$1" ] # 再來一個, 與上邊的程式碼塊作用相同.
# if /usr/bin/[ -z "$1" # 能夠工作, 但是還是給出一個錯誤訊息.
"vartify.sh" [New] 46L, 1086C written
root@client.example.com ~/yang # chmod 755 vartify.sh
root@client.example.com ~/yang # ./vartify.sh
No command-line arguments.
No command-line arguments.
No command-line arguments.
No command-line arguments.
root@client.example.com ~/yang # ./vartify.sh yangqilong
First command-line argument is yangqilong.
First command-line argument is yangqilong.
First command-line argument is yangqilong.
First command-line argument is yangqilong.
root@client.example.com ~/yang #
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22664653/viewspace-689631/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- linux中/bin和/sbin和/usr/bin和/usr/sbinLinux
- Linux下/bin, /sbin, /usr/bin, /usr/sbin 等的區別Linux
- 一分鐘看懂頭部 shell #!/usr/bin 命令
- /usr/bin和/usr/sbin有什麼區別
- /usr/bin/python與/usr/bin/env python的區別Python
- #!/usr/bin/env python與#!/usr/bin/python的區別Python
- /bin、/sbin、/usr/bin、/usr/sbin、/usr/local/sbin放置可執行檔案的區別
- #!/usr/bin/env pythonPython
- python中#!/usr/bin/python與#!/usr/bin/env python的區別Python
- /usr/bin/ld: cannot find -lopenblas
- -bash: /usr/local/bin/pod: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby: b...Framework
- /usr/bin/ld: cannot find -lmysqlclient_rMySqlclient
- 【jenkins】/usr/bin/env: php: No such file or directoryJenkinsPHP
- Sub-process /usr/bin/dpkg returned an error codeError
- Php cli模式下執行報錯/usr/bin/php: /usr/local/lib/libxml2.so.2: no version information available (required by /usr/bin/php)PHP模式XMLORMAIUI
- You don't have write permissions for the /usr/bin directory.
- 安裝pods提示Operation not permitted usr bin xcodeprojMITXCode
- bundler安裝失敗,Operation not permitted - /usr/bin/***MIT
- innobackupex:Error:xtrabackup child process has died at /usr/bin/innobackupexError
- /usr/bin/xauth: error in locking authority file錯誤Error
- Shell test 命令
- 一行命令搞定/usr/bin/perl^M: bad interpreter
- WSL:Sub-process /usr/bin/dpkg returned an error code (1)Error
- mac下/usr/local/bin No such file or directory問題解決Mac
- Authentication is required to run /usr/bin/x-terminal-emulator as rootUI
- 執行shell指令碼報錯:-bash: ./test1.sh: /bin/bash^M: ...指令碼
- /usr/bin/Xvnc: undefined symbol: pixman_composite_trapezoidsVNCUndefinedSymbol
- Shell學習【test命令】
- Starting MySQL * Couldn't find MySQL server (/usr/bin/mysqld_safe)MySqlServer
- Error: Could not load module '/usr/local/nagios/bin/ndo2ErroriOS
- code EACCESnpm ERR! syscall renamenpm ERR! path /usr/local/bin/webpack errno -13NPMWeb
- 安裝nodejs和grunt以後出現 /usr/bin/env: node: No such file or directoryNodeJS
- 記一次危險的操作——誤刪/usr/bin目錄
- INNOTOP退出時報異常glibc detected *** /usr/bin/perl: double free or corruption
- Linux下的一些重要目錄/proc, /sys, /SElinux, /bin, /usr/lib, /usr/local, /var, /tmp/etcLinux
- oracle11g:Prvf-0042: /usr/local/bin/ssh request by the client does not existOracleclient
- compass專案監控檔案報 /usr/bin/env 找不到檔案
- python升級帶來的yum異常:File "/usr/bin/yum", line 30Python