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

zip error – Nothing to do

The issue is that you have not provided a name for the zip-files it will create. This will create separate zipped directories for each of the subfolders tmp tmp_dkjg and tmp_dsf

What’s the meaning of the parameter -e for bash shell command line?

The -e option means “if any pipeline ever ends with a non-zero (‘error’) exit status, terminate the script immediately”. Since grep returns an exit status of 1 when it doesn’t find any match, it can cause -e to terminate the script even when there wasn’t a real “error”. If you want to keep the -e option, but also have a grep command that might validly find no … Read more

Variable interpolation in the shell

Use or or _ is a valid character in identifiers. Dot is not, so the shell tried to interpolate $filepath_newstap. You can use set -u to make the shell exit with an error when you reference an undefined variable.

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