Top "Bash" questions

For questions about scripts written for the Bash command shell.

Extract substring in Bash

Given a filename in the form someletters_12345_moreleters.ext, I want to extract the 5 digits and put them into a …

string bash shell substring
How to compare strings in Bash

How do I compare a variable to a string (and do something if they match)?

string bash
How do I iterate over a range of numbers defined by variables in Bash?

How do I iterate over a range of numbers in Bash when the range is given by a variable? I …

bash shell for-loop syntax
In the shell, what does " 2>&1 " mean?

In a Unix shell, if I want to combine stderr and stdout into the stdout stream for further manipulation, I …

bash shell unix redirect
How to specify the private SSH-key to use when executing shell command on Git?

A rather unusual situation perhaps, but I want to specify a private SSH-key to use when executing a shell (git) …

git bash shell ssh
Passing parameters to a Bash function

I am trying to search how to pass parameters in a Bash function, but what comes up is always how …

bash parameters arguments
How to change the output color of echo in Linux

I am trying to print a text in the terminal using echo command. I want to print the text in …

linux bash command-line echo terminal-color
How do I compare two string variables in an 'if' statement in Bash?

I'm trying to get an if statement to work in Bash (using Ubuntu): #!/bin/bash s1="hi" s2="hi" if ["$…

bash if-statement scripting
Redirect all output to file

I know that in Linux, to redirect output from the screen to a file, I can either use the > …

linux bash io-redirection
How do I reload .bashrc without logging out and back in?

If I make changes to .bashrc, how do I reload it without logging out and back in?

bash terminal reload profile