Linked Questions

86 votes
2 answers
113k views

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 ] &...
supertonsky's user avatar
37 votes
2 answers
30k views

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?
Jhonathan's user avatar
  • 3,765
13 votes
2 answers
3k views

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 ...
the_velour_fog's user avatar
6 votes
2 answers
3k views

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 ...
kjo's user avatar
  • 16.4k
1 vote
4 answers
4k views

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....
Haris's user avatar
  • 201
3 votes
1 answer
5k views

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"*...
Viesturs's user avatar
  • 993
3 votes
1 answer
2k views

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="" $...
Anon's user avatar
  • 425
0 votes
0 answers
35 views

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 unquoting ...
ahmet alp balkan's user avatar
535 votes
22 answers
284k views

I have two processes foo and bar, connected with a pipe: $ foo | bar bar always exits 0; I'm interested in the exit code of foo. Is there any way to get at it?
Michael Mrozek's user avatar
593 votes
7 answers
318k views

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 ...
RetroCode's user avatar
  • 6,079
350 votes
11 answers
754k views

I have a cron job that is scheduled to run every day. Other than changing the schedule, is there any other way to do a test run of the cron job right now to see if it works as intended? I know the ...
Ali's user avatar
  • 7,283
182 votes
1 answer
81k views

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 $...
kjo's user avatar
  • 16.4k
48 votes
7 answers
13k views

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" ...
Michael Durrant's user avatar
86 votes
3 answers
58k views

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 [[ $...
user3539's user avatar
  • 4,488
42 votes
9 answers
186k views

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.) ...
michelemarcon's user avatar

15 30 50 per page