Shell

The term 'shell' refers to a general class of text-based interactive command interpreters most often associated with the Unix & Linux operating systems. For questions about shell scripting, please use a more specific tag such as 'bash', 'powershell' or 'ksh'. Without a specific tag, a portable (POSIX-compliant) solution should be assumed, though using 'posix' in addition or 'sh' instead is preferable.

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
61 votes
20 answers
1.1K views
How to use SSH to run a local shell script on a remote machine?

I have to run a local shell script (windows/Linux) on a remote machine. I have SSH configured on both machine

avatar
Dusty
0 1 0 9
asked 07 September, 2021
54 votes
30 answers
437 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
909 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
621 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
59 votes
30 answers
2.5K views
How to exclude a directory in find . command

I'm trying to run a find command for all JavaScript files, but how do I exclude a specific directory? He

avatar
Nereida
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
853 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
53 votes
19 answers
1.4K views
How to delete from a text file, all lines that contain a specific string?

How would I use sed to delete all lines in a text file that contain a specific string?

avatar
Fabian
0 1 0 9
asked 07 September, 2021
56 votes
18 answers
2.4K views
How can I recursively find all files in current and subfolders based on wildcard matching?

How can I recursively find all files in current and subfolders based on wildcard matching?

avatar
Robt
0 1 0 9
asked 07 September, 2021
47 votes
16 answers
1.6K views
How to mkdir only if a directory does not already exist?

I am writing a shell script to run under the KornShell (ksh) on AIX. I would like to use the mkdir command to

avatar
Yolando
0 1 0 9
asked 07 September, 2021
48 votes
30 answers
1.1K 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
403 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