Linked Questions

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 ...
Honza Hejzl's user avatar
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 ...
Murphy's user avatar
  • 2,709
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?
AkshaiShah's user avatar
  • 3,669
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 ...
munish's user avatar
  • 8,237
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 ...
Javran's user avatar
  • 203
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 ...
Tim's user avatar
  • 107k
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 ...
Marc Le Bihan's user avatar
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 ...
Boris Däppen's user avatar
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 ...
Amr Kamel's user avatar
  • 121
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 ...
Tim's user avatar
  • 107k
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="...
Chicken Sandwich No Pickles's user avatar
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] ]] ...
bigstreet's user avatar
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 ...
Adam Katz's user avatar
  • 4,192