- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: If [ ] and [[ ]]
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-25-2005 06:53 AM
тАО01-25-2005 06:53 AM
I noticed that sometimes
"if [ $A = $B ]" is used and other times
"if [[ $A = $B ]]" is used. Is there a difference or is it just a personal choice?
TIA,
Ryan
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-25-2005 06:55 AM
тАО01-25-2005 06:55 AM
Solution- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-25-2005 06:59 AM
тАО01-25-2005 06:59 AM
Re: If [ ] and [[ ]]
And you cannot use boolean expressions with [[. You will need to use [ to use boolean operators
# S=1
# [[ $S -eq 10 -o $S -gt 10 ]]
ksh: syntax error: `-o' unexpected
# [ $S -eq 10 -o $S -gt 10 ]
#
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-25-2005 06:59 AM
тАО01-25-2005 06:59 AM
Re: If [ ] and [[ ]]
e.g. (and)
if [ ${A} = ${B} -a ${A} = ${C} ]
is written
if [[ ${A} = ${B} && ${A} = ${C} ]].
Similarly, -o (or) becomes ||.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-26-2005 07:53 AM
тАО01-26-2005 07:53 AM
Re: If [ ] and [[ ]]
> if [[ "toto" = toto* ]]; then echo equals; else echo "not equal"; fi
equals
> if [ "toto" = toto* ]; then echo equals; else echo "not equal"; fi
not equal
http://www.kornshell.com/doc/faq.html
Q10. What is the difference between [...] and [[...]]?
A10. The [[...]] is processed as part of the shell grammar
whereas [...] is processed like any other command.
Operators and operands are detected when the command is
read, not after expansions are performed. The shell does not
do word splitting or pathname generation inside [[...]].
This allows patterns to be specified for string matching
purposes.
- Tags:
- ksh