Linked Questions
13 questions linked to/from Why is `[` a shell builtin and `[[` a shell keyword?
2
votes
0
answers
468
views
What is the difference between test, [, and [[ in terms of binary vs. builtin? [duplicate]
It is often written:
/usr/bin/test is a synonym for /usr/bin/[
[[ is a bash improvement for [
test and [ are also builtins
I understand the difference between [ and [[ but I am confused with the ...
1
vote
0
answers
71
views
Conditional expressions in shell: What are the differences between [ vs [[ [duplicate]
I just wondered about some people writing
if [[ <expr> ]]; then ...
in answers here when I out of habit would use
if [ <expr> ]; then ...
Doing a quick research reveals that [[ ]] seems ...
144
votes
7
answers
30k
views
Why is cd not a program?
I've always wondered why cd isn't a program, but never managed to find the answer.
Anyone know why this is the case?
39
votes
3
answers
5k
views
What is the difference between [[ $a == z* ]] and [ $a == z* ]?
Is there is any difference between these two.
[[ $a == z* ]]
and
[ $a == z* ]
Can I have an example where they would have different outputs?
Furthermore, how does the working of [[ ]] differs ...
10
votes
3
answers
9k
views
is it possibe to change parent shell's working directory programmatically?
I want to write some code to allow me switching to some directories that I usually go to. Say this program is mycd, and /a/very/long/path/name is the directory that I want to go to.
So I can simply ...
13
votes
2
answers
6k
views
Differences between keyword, reserved word, and builtin?
From Make bash use external `time` command rather than shell built-in, Stéphane Chazelas wrote:
There is no time bash builtin. time is a keyword so you can do for instance time { foo; bar; }
We can ...
4
votes
2
answers
948
views
Two attempts of an if with an "and" are failing: if [ ... ] -a [ ... ] , if [[ ... && ... ]] Why?
In a bash script, I'm willing to check if a parameter has a boolean value ("true" or "false").
I'm attempting this in two scripts in two different ways, both failing.
I've checked ...
5
votes
2
answers
4k
views
call `time` with format option
I want to measure execution time of commands and get (to me) strange behavior of the time command.
I call time like it is mentioned in the examples of the manpages with the -f or --format option and ...
0
votes
1
answer
6k
views
./shell.sh: line 6: [: =~: binary operator expected
I'm trying to execute the following shell script, where I'm trying to keep executing a command in an infinite loop and until the output is not equal to a certain substring
checkDeviceStatus=$(adb ...
0
votes
2
answers
559
views
Why don't word splitting and filename expansion apply to the conditional expression within `[[ ... ]]`?
From Bash Reference Manual
Rule from Word Splitting section:
The shell scans the results of parameter expansion, command substitution, and arithmetic
expansion that did not occur within double ...
0
votes
1
answer
415
views
Shell script not picking up variable in if statement
I have some code that looks like this:
################### - Let's call this section 1
if [ -n "$STUFF_JAVA" ]; then
__LAUNCHER="$STUFF_JAVA"
else
__LAUNCHER="...
0
votes
2
answers
105
views
Getting an error in the if condition
I am just checking whether the password contains a small and capital case letter, I am getting an error at line 19.
myscript.sh:
#!bin/sh
read password
conditionarr=(0 0)
if [[ $password =~ [A-Z] ]]
...
2
votes
0
answers
48
views
Can't unalias then redefine as a function in the same conditional [duplicate]
Here is a simplified implementation of an issue in my bash/zsh aliases file:
alias foobar='echo bar' # this is out of my control
if true; then
unalias foobar
echo we got inside the conditional
...