Is there anything in Zsh like .bash_profile?

Yes, it’s called ~/.zshenv. Here’s how I have $JAVA_HOME set in ~/.zshenv: Keep in mind, however, that zsh is not bash, so just ’cause you have to source your .bash_profile every time you open a terminal does not mean that you have to do that with zsh. With zsh, I only have to re-source my ~/.zshenv when I make changes to it, and then only for terminals which … Read more

Check existence of input argument in a Bash shell script

It is: The $# variable will tell you the number of input arguments the script was passed. Or you can check if an argument is an empty string or not like: The -z switch will test if the expansion of “$1” is a null string or not. If it is a null string then the body is executed.

Bash command to sum a column of numbers

Using existing file: Using stdin: Edit: With some paste implementations you need to be more explicit when reading from stdin: <cmd> | paste -sd+ – | bc Options used: -s (serial) – merges all the lines into a single line -d – use a non-default delimiter (the character + in this case)

How can I check if a program exists from a Bash script?

Answer POSIX compatible: Example use: For Bash specific environments: Explanation Avoid which. Not only is it an external process you’re launching for doing very little (meaning builtins like hash, type or command are way cheaper), you can also rely on the builtins to actually do what you want, while the effects of external commands can easily vary from system to system. … Read more

How to remove last n characters from a string in Bash?

First, it’s usually better to be explicit about your intent. So if you know the string ends in .rtf, and you want to remove that .rtf, you can just use var2=${var%.rtf}. One potentially-useful aspect of this approach is that if the string doesn’t end in .rtf, it is not changed at all; var2 will contain … Read more

What does set -e mean in a bash script?

From help set : But it’s considered bad practice by some (bash FAQ and irc freenode #bash FAQ authors). It’s recommended to use: to run do_something function when errors occur. See http://mywiki.wooledge.org/BashFAQ/105

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)