Tag: bash

55 votes
16 answers
1.9K views
How to remove a directory from git repository?

I have 2 directories on my GitHub repository. I'd like to delete one of them. How could I do that without

avatar
Venice
0 1 0 9
asked 07 September, 2021
68 votes
9 answers
1.1K views
How does "cat << EOF" work in bash?

I needed to write a script to enter multi-line input to a program (psql). After a bit of googling, I found th

avatar
Eddie
0 1 0 9
asked 07 September, 2021
56 votes
9 answers
2K views
Redirect all output to file in Bash

I know that in Linux, to redirect output from the screen to a file, I can either use the > or tee. How

avatar
Cortez
0 1 0 9
asked 07 September, 2021
50 votes
30 answers
2.1K views
Pipe to/from the clipboard in a Bash script

Is it possible to pipe to/from the clipboard in Bash? Whether it is piping to/from a device handle or using an

avatar
Suzan
0 1 0 9
asked 07 September, 2021
60 votes
10 answers
1.8K views
How to redirect output to a file and stdout

In bash, calling foo would display any output from that command on the stdout. Calling foo > output would

avatar
Kurtis
0 1 0 9
asked 07 September, 2021
56 votes
27 answers
503 views
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.0

avatar
Luis
0 1 0 9
asked 07 September, 2021
65 votes
15 answers
1.2K views
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 in (pepti

avatar
Eddie
0 1 0 9
asked 07 September, 2021
58 votes
30 answers
735 views
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 a red color. How

avatar
Dusty
0 1 0 9
asked 07 September, 2021
58 votes
30 answers
1.5K views
How do I test if a variable is a number in Bash?

I just can't figure out how do I make sure an argument passed to my script is a number or not. All I wan

avatar
Nidia
0 1 0 9
asked 07 September, 2021
56 votes
7 answers
2.9K views
When do we need curly braces around shell variables?

In shell scripts, when do we use {} when expanding variables? For example, I have seen the following: var=10

avatar
Jesenia
0 1 0 9
asked 07 September, 2021
56 votes
12 answers
849 views
How to &apos;grep&apos; a continuous stream?

Is that possible to use grep on a continuous stream? What I mean is sort of a tail -f <file> command, b

avatar
Lorenzo
0 1 0 9
asked 07 September, 2021
54 votes
22 answers
3K views
Extract substring in Bash

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

avatar
Wilber
0 1 0 9
asked 07 September, 2021
56 votes
10 answers
2.9K views
How do I pause my shell script for a second before continuing?

I have only found how to wait for user input. However, I only want to pause so that my while true doesn't

avatar
Benton
0 1 0 9
asked 07 September, 2021
59 votes
17 answers
2.7K views
Add line break to &apos;git commit -m&apos; from the command line

I am using Git from the command line and am trying to add a line break to the commit message (using git commit

avatar
Denese
0 1 0 9
asked 07 September, 2021
54 votes
16 answers
792 views
Count number of lines in a git repository

How would I count the total number of lines present in all the files in a git repository? git ls-files gives

avatar
Joseph
0 1 0 9
asked 07 September, 2021
57 votes
8 answers
1.9K views
What does set -e mean in a bash script?

I'm studying the content of this preinst file that the script executes before that package is unpacked fr

avatar
Lorenzo
0 1 0 9
asked 07 September, 2021
56 votes
18 answers
1.5K views
How to call one shell script from another shell script?

I have two shell scripts, a.sh and b.sh. How can I call b.sh from within the shell script a.sh?

avatar
Xavier
0 1 0 9
asked 07 September, 2021
66 votes
9 answers
3K views
Assigning default values to shell variables with a single command in bash

I have a whole bunch of tests on variables in a bash (3.00) shell script where if the variable is not set, the

avatar
Kurtis
0 1 0 9
asked 07 September, 2021
58 votes
21 answers
1.3K views
Get current directory name (without full path) in a Bash script

How would I get just the current working directory name in a bash script, or even better, just a terminal comm

avatar
Patsy
0 1 0 9
asked 07 September, 2021
57 votes
10 answers
1.2K views
Replace one substring for another string in shell script

I have "I love Suzi and Marry" and I want to change "Suzi" to "Sara". #!/bin/bash firstString="I love Suzi an

avatar
Shantay
0 1 0 9
asked 07 September, 2021