Linked Questions

80 votes
2 answers
102k views

What do square brackets mean without the "if" on the left? [duplicate]

As far as I know, square brackets are used to enclose an expression usually in if else statements. But I found square brackets being used without the "if" as follows: [ -r /etc/profile.d/java.sh ] &...
11 votes
2 answers
2k views

Why does this bash conditional check work with [[ -n .. ]] but not [ -n .. ]? [duplicate]

I have a script that fails to detect zero length strings,the script uses [ -n $value ] in a bash conditional expression, i.e. #!/usr/bin/env bash value="" if [ -n $value ] then echo "value is ...
13 votes
2 answers
7k views

When should I use [ vs [[ in Bash (single vs double brackets)? [duplicate]

Possible Duplicate: using single or double bracket - bash When should I use a single bracket? [ When should I use double brackets? [[ Are both POSIX compliant?
  • 3,305
6 votes
2 answers
2k views

[ vs [[ : which one to use in bash scripts? [duplicate]

The zsh man page, in its section on test (aka [), explicitly advises against using it at all, and urges readers to use [[ whenever possible. The relevant section states: The command attempts to ...
  • 13.9k
1 vote
4 answers
4k views

Linux shell script check command success [duplicate]

I need to check the command executed is success or not, I have place the below code in test.sh run it, which give the out by listing the content of /home but there is a warning ./test.sh: 3: ./test....
  • 191
2 votes
1 answer
4k views

Difference between [ and [[ in if statements [duplicate]

The following code if [ $a == "apple" ]; then echo "True" else echo "False" fi outputs "True" ("False") if a="apple" (a="plum"). The comparison fails if one uses wildcards: if [ $a == "appl"...
  • 903
1 vote
1 answer
334 views

What's the difference between test command and individual conditional expression surrounded by [[]]? [duplicate]

I am learning the zsh in the conditional expressions part, and I found some unreasonable output. For example: $ mkdir emptyspace && cd emptyspace $ var_assigned_with_emptystring="" $...
  • 375
0 votes
0 answers
34 views

Double-quoting (vs not) variables in [ and [[ [duplicate]

I'm using shfmt (a tool to tidy up bash scripts). It has a -s (simplify) option that rewrites a line like: if [[ -n "$out" ]] to unquoted version: if [[ -n $out ]] I'm actually curious if ...
509 votes
7 answers
239k views

What is the difference between the Bash operators [[ vs [ vs ( vs ((?

I am a little bit confused on what do these operators do differently when used in bash (brackets, double brackets, parenthesis and double parenthesis). [[ , [ , ( , (( I have seen people use them on ...
  • 5,239
290 votes
11 answers
567k views

how can I make cron run a job right now, for testing/debugging? without changing the schedule!

I have a cron job that is scheduled to run everyday, other than changing the schedule, is there any other way to do a test run of the command right now to see if it works as intended? EDIT: (from ...
  • 6,343
170 votes
1 answer
70k views

When is double-quoting necessary?

The old advice used to be to double-quote any expression involving a $VARIABLE, at least if one wanted it to be interpreted by the shell as one single item, otherwise, any spaces in the content of $...
  • 13.9k
47 votes
7 answers
12k views

Is test or [ or [[ more portable both between bash shells and between other shells?

I see I can do $ [ -w /home/durrantm ] && echo "writable" writable or $ test -w /home/durrantm && echo "writable" writable or $ [[ -w /home/durrantm ]] && echo "writable" ...
71 votes
3 answers
44k views

What's the difference between single and double equal signs (=) in shell comparisons?

Read that for comparing strings inside if we need to use double square brackets. Some books says that comparison can be done by =. But it works with the == too. #!/bin/bash a="hello" b="world" if [[ $...
  • 4,138
38 votes
9 answers
144k views

How to check password with Linux?

I want to check, from the linux command line, if a given cleartext password is the same of a crypted password on a /etc/shadow (I need this to authenticate web users. I'm running an embedded linux.) ...
42 votes
3 answers
78k views

Comparing integers: arithmetic expression or conditional expression

In Bash, two integers can be compared using conditional expression arg1 OP arg2 OP is one of -eq, -ne, -lt, -le, -gt, or -ge. These arithmetic binary operators return true if arg1 is equal ...
  • 93.5k

15 30 50 per page