How do I compare two string variables in an ‘if’ statement in Bash?
For string equality comparison, use: For string does NOT equal comparison, use: For the a contains b, use: (and make sure to add spaces between the symbols): Bad: Good:
For string equality comparison, use: For string does NOT equal comparison, use: For the a contains b, use: (and make sure to add spaces between the symbols): Bad: Good:
As @kirbyfan64sos notes in a comment, /home is NOT your home directory (a.k.a. home folder): The fact that /home is an absolute, literal path that has no user-specific component provides a clue. While /home happens to be the parent directory of all user-specific home directories on Linux-based systems, you shouldn’t even rely on that, given that this differs across platforms: for instance, the equivalent directory on macOS is /Users. What all Unix … Read more
Try ssh -t -t(or ssh -tt for short) to force pseudo-tty allocation even if stdin isn’t a terminal. See also: Terminating SSH session executed by bash script From ssh manpage:
Change into note the space.
This is called heredoc format to provide a string into stdin. See https://en.wikipedia.org/wiki/Here_document#Unix_shells for more details. From man bash: Here Documents This type of redirection instructs the shell to read input from the current source until a line containing only word (with no trailing blanks) is seen. All of the lines read up to that point are then used as the … Read more
You can set the internal field separator (IFS) variable, and then let it parse into an array. When this happens in a command, then the assignment to IFS only takes place to that single command’s environment (to read ). It then parses the input according to the IFS variable value into an array, which we can then iterate over. This example will parse … Read more
test‘s string equality operator doesn’t do globs.
The POSIX specification for find says: -mtimen The primary shall evaluate as true if the file modification time subtracted from the initialization time, divided by 86400 (with any remainder discarded), is n. Interestingly, the description of find does not further specify ‘initialization time’. It is probably, though, the time when find is initialized (run). In the descriptions, wherever n is used as a primary argument, … Read more
Actually, your second attempt works for me in bash 3 and 4: However, to talk theory for a second, it all has to do with how bash interprets the expression as a whole. As long as the regular-expression characters themselves aren’t quoted, the rest of the expression can be quoted without side-effects: but perhaps the … Read more
Try following these if these might help: Since your installation works on the terminal you installed, all the exports you did, work on the current bash and its child process. but is not spawned to new terminals. env variables are lost if the session is closed; using .bash_profile, you can make it available in all sessions, since when a bash session starts, it … Read more