Top "Bash" questions

For questions about scripts written for the Bash command shell.

How to concatenate string variables in Bash

In PHP, strings are concatenated together as follows: $foo = "Hello"; $foo .= " World"; Here, $foo becomes "Hello World". How is this …

bash shell syntax concat string-concatenation
How can I check if a directory exists in a Bash shell script?

What command can be used to check if a directory exists or not, within a Bash shell script?

bash shell unix posix
How do I tell if a regular file does not exist in Bash?

I've used the following script to see if a file exists: #!/bin/bash FILE=$1 if [ -f $FILE ]; then echo "File $…

bash file-io scripting
Echo newline in Bash prints literal \n

In Bash, tried this: echo -e "hello\nworld" But it doesn't print a newline, only \n. How can I make …

bash echo newline
How to check if a string contains a substring in Bash

I have a string in Bash: string="My string" How can I test if it contains another string? if [ $string ?? …

string bash shell substring sh
How do I set a variable to the output of a command in Bash?

I have a pretty simple script that is something like the following: #!/bin/bash VAR1="$1" MOREF='sudo run command against $…

bash shell command-line
How to get the source directory of a Bash script from within the script itself?

How do I get the path of the directory in which a Bash script is located, inside that script? I …

bash directory
Looping through the content of a file in Bash

How do I iterate through each line of a text file with Bash? With this script: echo "Start!" for p …

linux bash loops unix io