Tag: bash

61 votes
14 answers
307 views
How to echo shell commands as they are executed

In a shell script, how do I echo all shell commands called and expand any variable names? For example, given

avatar
Kisha
0 1 0 9
asked 07 September, 2021
48 votes
14 answers
2.3K views
Defining a variable with or without export

What is export for? What is the difference between: export name=value and name=value

avatar
Basil
0 1 0 9
asked 07 September, 2021
61 votes
14 answers
782 views
How to reload .bash_profile from the command line?

How can I reload .bash_profile from the command line? I can get the shell to recognize changes to .bas

avatar
Bryan
0 1 0 9
asked 07 September, 2021
53 votes
23 answers
1.4K views
How can I declare and use Boolean variables in a shell script?

I tried to declare a Boolean variable in a shell script using the following syntax: variable=$false variable

avatar
Freida
0 1 0 9
asked 07 September, 2021
62 votes
14 answers
1.7K views
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 get thi

avatar
Adolfo
0 1 0 9
asked 07 September, 2021
54 votes
30 answers
439 views
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

avatar
Deedee
0 1 0 9
asked 07 September, 2021
58 votes
21 answers
911 views
How to convert a string to lower case in Bash?

Is there a way in bash to convert a string into a lower case string? For example, if I have: a="Hi all" I

avatar
Tuan
0 1 0 9
asked 07 September, 2021
66 votes
12 answers
2.5K views
Difference between sh and bash

When writing shell programs, we often use /bin/sh and /bin/bash. I usually use bash, but I don't know wha

avatar
Luis
0 1 0 9
asked 07 September, 2021
64 votes
11 answers
623 views
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 e

avatar
Virgil
0 1 0 9
asked 07 September, 2021
61 votes
30 answers
1.2K views
How do I prompt for Yes/No/Cancel input in a Linux shell script?

I want to pause input in a shell script, and prompt the user for choices. The standard Yes, No, or Cancel type

avatar
Kristopher
0 1 0 9
asked 07 September, 2021
61 votes
20 answers
3.1K views
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: f

avatar
Venice
0 1 0 9
asked 07 September, 2021
55 votes
30 answers
855 views
How can I count all the lines of code in a directory recursively?

We've got a PHP application and want to count all the lines of code under a specific directory and its su

avatar
Deedee
0 1 0 9
asked 07 September, 2021
58 votes
20 answers
1.7K views
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 know I can do this

avatar
Benton
0 1 0 9
asked 07 September, 2021
58 votes
16 answers
1K views
How to reload .bashrc settings without logging out and back in again?

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

avatar
Freida
0 1 0 9
asked 07 September, 2021
58 votes
30 answers
2.5K views
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 gave the first parameter

avatar
Basil
0 1 0 9
asked 07 September, 2021
59 votes
14 answers
1.1K views
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 r

avatar
Elicia
0 1 0 9
asked 07 September, 2021
48 votes
30 answers
1.2K views
How do I split a string on a delimiter in Bash?

I have this string stored in a variable: IN="[email protected];[email protected]" Now I would like to split the stri

avatar
Lynette
0 1 0 9
asked 07 September, 2021
62 votes
18 answers
405 views
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 can

avatar
Renaldo
0 1 0 9
asked 07 September, 2021
51 votes
26 answers
2K views
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 ?? &ap

avatar
Sena
0 1 0 9
asked 07 September, 2021
51 votes
30 answers
1.5K views
How to concatenate string variables in Bash

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

avatar
Luis
0 1 0 9
asked 07 September, 2021