How to compare strings in Bash

Using variables in if statements If you want to do something when they don’t match, replace = with !=. You can read more about string operations and arithmetic operations in their respective documentation. Why do we use quotes around $x? You want the quotes around $x, because if it is empty, your Bash script encounters … Read more

How to create a file in Linux from terminal window? [closed]

Depending on what you want the file to contain: touch /path/to/file for an empty file somecommand > /path/to/file for a file containing the output of some command. eg: grep –help > randomtext.txt echo “This is some text” > randomtext.txt nano /path/to/file or vi /path/to/file (or any other editor emacs,gedit etc)It either opens the existing one for editing or creates & opens … Read more

How to split a string into an array in Bash?

Note that the characters in $IFS are treated individually as separators so that in this case fields may be separated by either a comma or a space rather than the sequence of the two characters. Interestingly though, empty fields aren’t created when comma-space appears in the input because the space is treated specially. To access … Read more