Top "Bash" questions

For questions about scripts written for the Bash command shell.

Read a file line by line assigning the value to a variable

I have the following .txt file: Marco Paolo Antonio I want to read it line-by-line, and for each line I …

bash
How to permanently set $PATH on Linux/Unix?

I'm trying to add a directory to my path so it will always be in my Linux path. I've tried: …

linux bash unix path zsh
Extract filename and extension in Bash

I want to get the filename (without extension) and the extension separately. The best solution I found so far is: …

bash string filenames
How do I parse command line arguments in Bash?

Say, I have a script that gets called with this line: ./myscript -vfd ./foo/bar/someFile -o /fizz/someOtherFile or …

bash command-line scripting arguments getopts
YYYY-MM-DD format date in shell script

I tried using $(date) in my bash shell script, however, I want the date in YYYY-MM-DD format. How do I …

bash shell date strftime
How to count lines in a document?

I have lines like these, and I want to know how many lines I actually have... 09:16:39 AM all 2.00 0.00 4.00 0.00 0.00 0.00 0.00 0.00 94.00 09:16:40 AM all 5.00 0.00 0.00 4.00 0.00 0.00 0.00 0.00 91.00 09:16:41 …

linux bash command-line scripting
How to check if a variable is set in Bash?

How do I know if a variable is set in Bash? For example, how do I check if the user …

bash shell variables
How to trim whitespace from a Bash variable?

I have a shell script with this code: var=`hg st -R "$path"` if [ -n "$var" ]; then echo $var fi …

string bash variables trim
Check existence of input argument in a Bash shell script

I need to check the existence of an input argument. I have the following script if [ "$1" -gt "-1" ] then echo …

bash shell
Loop through an array of strings in Bash?

I want to write a script that loops through 15 strings (array possibly?) Is that possible? Something like: for databaseName in …

arrays bash shell