Tag: shell

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
850 views
How to 'grep' 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
62 votes
22 answers
750 views
Use grep --exclude/--include syntax to not grep through certain files

I'm looking for the string foo= in text files in a directory tree. It's on a common Linux machine, I

avatar
Venice
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
54 votes
28 answers
1.7K views
Shell command to tar directory excluding certain files/folders

Is there a simple shell command/script that supports excluding certain files/folders from being archived? I h

avatar
Hilario
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
53 votes
30 answers
2.5K views
Shell command to sum integers, one per line?

I am looking for a command that will accept (as input) multiple lines of text, each line containing a single i

avatar
Robt
0 1 0 9
asked 07 September, 2021
62 votes
11 answers
1.1K views
How do I put an already-running process under nohup?

I have a process that is already running for a long time and don't want to end it. How do I put it under

avatar
Wilfredo
0 1 0 9
asked 07 September, 2021
54 votes
12 answers
2.8K views
Should I put #! (shebang) in Python scripts, and what form should it take?

Should I put the shebang in my Python scripts? In what form? #!/usr/bin/env python or #!/usr/local/bin/py

avatar
Omar
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
61 votes
14 answers
308 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
783 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